6

我有控制器通过它导航到home.jsp主页.jsp 现在有两个按钮FindEmployeeByid FindEmployeeByName,因为我点击 FindEmployeeByid 新弹出窗口已打开,但在弹出窗口中我收到此消息The requested resource (/EmployeeWebSpring/search/Search.jsp) is not available.,因为在 Search.jsp 中我使用了 spring 的表单标签所以它无法获取模型对象,所以请告诉我如何执行此操作以打开一个输入字段处于活动状态的弹出窗口,以便我可以提交数据并对该数据执行一些操作

这是我的控制器

    package com.nousinfo.tutorial.controllers;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.nousinfo.tutorial.model.EmployeeForm;
import com.nousinfo.tutorial.service.impl.EmployeeServiceImpl;
import com.nousinfo.tutorial.service.model.EmployeeBO;

@Controller
@RequestMapping("/search")
public class SearchEmployeeController {

    private EmployeeServiceImpl employeeServiceImpl;

    public void setEmployeeServiceImpl(EmployeeServiceImpl employeeServiceImpl) {
        this.employeeServiceImpl = employeeServiceImpl;
    }



    @RequestMapping(value = "/searchspring", method = RequestMethod.GET)
    public String view(@Validated EmployeeForm employeeForm)
            throws Exception {
    return "home";
    }


    @RequestMapping(value = "/employeeNo", method = RequestMethod.POST)
    public ModelAndView searchByEmpNo(
            @ModelAttribute("employeeForm") EmployeeForm employeeForm)
            throws Exception {
        ModelAndView model = new ModelAndView();
        model.addObject("employeeForm", employeeForm);
        Long i = Long.parseLong(employeeForm.getEmployeeNumber());

        EmployeeBO employeeBO = employeeServiceImpl.getEmployee(i);
        System.out.println(employeeBO);
        model.addObject("employeeBO", employeeBO);

        model.setViewName("EmployeeDetail");
        return model;
    }

    @RequestMapping(value = "/empByName", method = RequestMethod.POST)
    public ModelAndView searchByEmployeeName(
            @ModelAttribute("employeeForm") EmployeeForm employeeForm) {
        ModelAndView model = new ModelAndView();
        model.addObject("employeeForm", employeeForm);
        List<EmployeeBO> employeeBOs = employeeServiceImpl
                .findEmployees(employeeForm.getFirstName());
        model.addObject("listEmployeeBO", employeeBOs);
        model.setViewName("EmployeeList");
        return model;

    }

    @RequestMapping(value = "/empByDeptId", method = RequestMethod.POST)
    public ModelAndView searchByDeptId(
            @ModelAttribute("employeeForm") EmployeeForm employeeForm) {
        ModelAndView model = new ModelAndView();
        model.addObject("employeeForm", employeeForm);
        List<EmployeeBO> employeeBOs = employeeServiceImpl
                .getAllEmployeeByDeptid(employeeForm.getDepartmentId());
        model.addObject("listEmployeeBO", employeeBOs);
        model.setViewName("EmployeeList");

        return model;

    }

}

这是我的家.jsp

  <%@page import="java.util.List"%>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="css/style.css" type="text/css"></link>
<link rel="stylesheet" href="css/styles.css" type="text/css"></link>
<title>Home</title>
<script type="text/javascript">
    function LoadByName(windowHeight, windowWidth) {
        var centerWidth = (window.screen.width - windowWidth) / 2;
        var centerHeight = (window.screen.height - windowHeight) / 2;
        newWindow = window.open('Search.jsp', 'mywindow',
                'resizable=0,width=' + windowWidth + ',height=' + windowHeight
                        + ',left=' + centerWidth + ',top=' + centerHeight);
        newWindow.divHiding(1);
        newWindow.focus();
    }
    function LoadById(windowHeight, windowWidth) {
        var centerWidth = (window.screen.width - windowWidth) / 2;
        var centerHeight = (window.screen.height - windowHeight) / 2;
        newWindow = window.open('Search.jsp', 'mywindow',
                'resizable=0,width=' + windowWidth + ',height=' + windowHeight
                        + ',left=' + centerWidth + ',top=' + centerHeight);
        newWindow.divHiding(2);
        newWindow.focus();
        return newWindow.name;
    }

    function loadName(name) {
        this.firstName = name;
        window.location = 'http://localhost:8080/EmployeeWebApp/GetEmployeeServlet?key1='
                + encodeURIComponent(firstName);
    }
    function loadId(id) {
        this.id = id;
        window.location = 'http://localhost:8080/EmployeeWebApp/GetEmployeeServlet?key2='
                + encodeURIComponent(id);
    }
</script>
</head>
<table width="951" height="116" border="0" align="center">
    <tr>
        <td width="961" height="112" align="center" bgcolor="#99CCFF"><h2>NOUS
                INFOSYSTEMS</h2></td>
        <td width="266" height="112" align="center" bgcolor="#FFFFFF"><img
            src="image/emps.jpg" alt="1" width="266" height="84" /></td>
    </tr>
</table>

<p>&nbsp;</p>
<table width="949" height="183" border="0" align="center">
    <tr>
        <td width="943" height="43"><input id="findid" name="button"
            type="submit" value="Find Employee By Number or ID"
            onClick="LoadById(250,500)" /></td>
    </tr>
    <tr>
        <td height="43"><input id="findname" name="submit2" type="button"
            value="Find Employee By Name" onClick="LoadByName(250,500)" /></td>
    </tr>
    <tr>
        <td><form id="form2" action="get.spring" method="get">
                <input type="submit" name="submit3" value="Get All Employees" />
            </form></td>
    </tr>
    <tr>
        <td><form id="form3" action="CreateEmployee.jsp">
                <input type="submit" name="submit3" value="Create An Employee" />
            </form></td>
    </tr>
</table>
<p>&nbsp;</p>
<br>
<br>
<body>
    <form>
        <table width="725" border="1" align="center" cellpadding="5"
            cellspacing="5">
            <tr>
                <th width="118">EmployeeNumber</th>
                <th width="118">First Name</th>
                <th width="118">Last Name</th>
                <th width="118">Title</th>
                <th width="118">Address1</th>
                <th width="118">Address2</th>
                <th width="118">City</th>
                <th width="118">Details</th>
            </tr>
            <c:forEach var="employeeBO" items="${model.listEmployeeBO}">
                <tr>

                    <td>${employeeBO.employeeNumber}</td>

                    <td>${employeeBO.firstName}</td>

                    <td>${employeeBO.lastName}</td>

                    <td>${employeeBO.title}</td>

                    <td>${employeeBO.address1}</td>

                    <td>${employeeBO.address2}</td>

                    <td>${employeeBO.city}</td>


                </tr>
            </c:forEach>

        </table>
        <table>
            <tr>

                <td></td>
            </tr>
        </table>
    </form>
</body>
</html>

这是我的 search.jsp

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>

<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<fmt:setBundle basename="ApplicationResources" />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Employee Search Page</title>

</head>
<body>
    <form:form action="/EmployeeWebSpring/search/empByName"  commandName="employeeForm" method="post">
        <table border="0">



            <tr>
                <td>Employee_ID</td>
                <td><form:input path="employeeNumber"  /></td>
                <td><input type="submit" name="method" value="FindById" /></td>
            </tr>
            <tr>
                <td>Employee_Name</td>
                <td><form:input path="firstName" /></td>
                <td><input type="submit" name="method" value="FindByName" /></td>
            </tr>


            <tr>
                <td>Employee_Name</td>
                <td><form:input path="departmentId" /></td>
                <td><input type="submit" name="method" value="FindByDeptNO" /></td>
            </tr>
            <tr>
                <td colspan="2" align="center"><font size=3>For
                        Searching the employees by<b>Employee Name</b><br />you can use %
                        match all the records with the given pattern
                </font><br /> <font size="2"> <i>e.g <b> for search by</b>EmployeeName<br />
                            matches alL the employees whose name starts with character <b>S</b></i></font></td>
            </tr>
        </table>
    </form:form>
</body>
</html>
4

1 回答 1

5

您可以在java脚本中执行以下操作并运行您的java脚本函数,因为您的函数运行它控制控制器,您可以提供jsp视图或任何视图

<script>
    function popup() {
        window.open("../popup/searchspring", 'window', 'width=200,height=100');
    }
</script> 

在控制器中你必须做这样的事情,这会将你的请求导航到所需的页面,因为在 spring 控制器中决定视图页面的导航

 @RequestMapping(value = "/searchspring", method = RequestMethod.GET)
    public String view(Model model) throws Exception {
        EmployeeBO employeeBO = new EmployeeBO();
        model.addAttribute("employeeBO", employeeBO);
        return "EmployeeForm";
    }
于 2013-02-27T12:00:05.610 回答