2013-01-07 23 views
6

tôi có bộ điều khiển thông qua đó nó hướng đến home.jsp trong nhà .jsp có hai nút FindEmployeeByidFindEmployeeByName nay như tôi bấm vào FindEmployeeByid cửa sổ popup mới được mở ra nhưng trong cửa sổ pop tôi đã nhận thông điệp này The requested resource (/EmployeeWebSpring/search/Search.jsp) is not available., bởi vì trong Search.jsp tôi đã sử dụng thẻ form của spring nên nó không thể lấy đối tượng model vì vậy plz cho biết cách tôi có thể thực hiện điều này để mở một cửa sổ pop với các trường đầu vào hoạt động để tôi có thể gửi dữ liệu thực hiện một số thao tác trên đó dữ liệuMở Một cửa sổ pop vào mùa xuân

đây là bộ điều khiển của tôi

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; 

    } 

} 

đây là home.jsp tôi

<%@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> 

và đây là search.jsp tôi

<%@ 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> 
+1

Có thể bạn có thể sử dụng javascript để gửi biểu mẫu, thay vì hành động biểu mẫu thông thường. – shazinltc

+0

@shazinltc vấn đề được giải quyết không cần điều đó nhưng nếu bạn có thể plz cho biết có nghĩa là sau khi thành công mở một search.jsp trong cửa sổ pop bây giờ tôi đã sử dụng thẻ div bây giờ dựa trên nút bấm tôi muốn hiển thị thẻ div tôi có java script nhưng thông qua "newWindow = window.open ('../ search/searchPage', 'mywindow',)" và "newWindow.showDiv (1)" trong search.jsp im không thể nhận giá trị 1 tại sao? – henrycharles

+0

@henrycharles xin vui lòng nếu bạn đã giải quyết vấn đề của bạn đăng một câu trả lời cho nó để những người khác có thể giải quyết vấn đề tương tự, liên quan. –

Trả lời

3

Bạn có thể làm như sau trong script java và chạy chức năng kịch bản java của bạn như chức năng của bạn chạy nó mất kiểm soát để điều khiển, của họ, bạn có thể cung cấp cái nhìn jsp hoặc bất kỳ xem

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

và điều khiển bạn phải làm một cái gì đó như thế này mà sẽ di chuyển theo yêu cầu của bạn để mong muốn gây ra trang trong kiểm soát xuân ler quyết định điều hướng của các trang xem

@RequestMapping(value = "/searchspring", method = RequestMethod.GET) 
    public String view(Model model) throws Exception { 
     EmployeeBO employeeBO = new EmployeeBO(); 
     model.addAttribute("employeeBO", employeeBO); 
     return "EmployeeForm"; 
    } 
Các vấn đề liên quan