2013-01-07 10 views
6

ho regolatore attraverso il quale navigare home.jsp in casa .jsp ci sono due pulsante FindEmployeeByidFindEmployeeByName ora come faccio clic su FindEmployeeByid nuova finestra pop-up viene aperta ma in finestra pop ho ottenuto questo messaggio The requested resource (/EmployeeWebSpring/search/Search.jsp) is not available., perché in Search.jsp ho usato il tag form di spring in modo che non sia in grado di ottenere l'oggetto del modello in modo da dire come posso eseguire questa operazione per aprire una finestra pop con i campi di input attivi in ​​modo che possa inviare i dati eseguendo qualche operazione su quello datiaprire una finestra a comparsa in primavera

questo è il mio controller

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; 

    } 

} 

questo è il mio home.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> 

e questo è il mio 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> 
+1

Potrebbe essere possibile utilizzare javascript per inviare il modulo, piuttosto che un'azione modulo convenzionale. – shazinltc

+0

il problema @shazinltc non è risolto, ma se si può dire che significa dopo aver aperto con successo un search.jsp nella finestra pop ora ho usato il tag div ora basato sul clic del pulsante voglio mostrare il tag div ho lo script java ma attraverso questo "newWindow = window.open ('../ search/searchPage', 'mywindow',)" e "newWindow.showDiv (1)" in search.jsp non sono in grado di ottenere il valore di 1 perché? – henrycharles

+0

@henrycharles, per favore, se hai risolto il tuo problema posta una risposta in modo che altri possano risolvere problemi simili, saluti. –

risposta

3

È possibile effettuare le seguenti operazioni in java script ed eseguire la funzione java script come la vostra funzione eseguirlo prende il controllo di controllore, la loro è possibile fornire la vista JSP o qualsiasi vista

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

e controller che dovete fare qualcosa di simile, che navigherà la richiesta a causa pagina desiderata nel controllo primavera Decidi la navigazione delle pagine di visualizzazione

@RequestMapping(value = "/searchspring", method = RequestMethod.GET) 
    public String view(Model model) throws Exception { 
     EmployeeBO employeeBO = new EmployeeBO(); 
     model.addAttribute("employeeBO", employeeBO); 
     return "EmployeeForm"; 
    } 
Problemi correlati