2013-01-07 10 views
6

में एक पॉप विंडो खोलें मैं नियंत्रक के माध्यम से जो इसे घर में home.jsp पर नेविगेट है .jsp अब मैं FindEmployeeByid नया पॉपअप विंडो पर क्लिक करें के रूप में खोला गया है, लेकिन पॉप विंडो में मैं इस संदेश को The requested resource (/EmployeeWebSpring/search/Search.jsp) is not available. मिला है, क्योंकि दो बटन FindEmployeeByidFindEmployeeByName है Search.jsp में मैंने वसंत के फॉर्म टैग का उपयोग किया है, इसलिए यह मॉडल ऑब्जेक्ट प्राप्त करने में सक्षम नहीं है, इसलिए कृपया बताएं कि मैं इनपुट फ़ील्ड सक्रिय के साथ एक पॉप विंडो खोलने के लिए इसे कैसे कर सकता हूं ताकि मैं उस डेटा को कुछ ऑपरेशन कर सकूं डेटावसंत

यह मेरा नियंत्रक है

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; 

    } 

} 

यह मेरा 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> 

है और यह मेरा 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

हो सकता है कि आप एक पारंपरिक फॉर्म कार्रवाई के बजाय फ़ॉर्म सबमिट करने के लिए जावास्क्रिप्ट का उपयोग कर सकें। – shazinltc

+0

@shazinltc समस्या को हल करने की कोई ज़रूरत नहीं है, लेकिन यदि आप बता सकते हैं कि पॉप विंडो में search.jsp को सफलतापूर्वक खोलने के बाद अब मैं बटन टैग के आधार पर div टैग का उपयोग कर चुका हूं, तो मैं div टैग को दिखाना चाहता हूं, मेरे पास जावा स्क्रिप्ट है लेकिन इस "newWindow = window.open ('../ search/searchPage', 'mywindow',)" और "newwindow.showDiv (1)" के माध्यम से search.jsp में 1 का मूल्य प्राप्त करने में सक्षम नहीं है? – henrycharles

+0

@henrycharles कृपया अगर आपने अपनी समस्या हल कर दी है तो इसका जवाब पोस्ट करें ताकि अन्य समान समस्याएं हल कर सकें। –

उत्तर

3

आप जावा स्क्रिप्ट में निम्न कार्य करें और अपने समारोह को चलाने के रूप में यह करने के लिए नियंत्रण लेता है अपने जावा स्क्रिप्ट समारोह चला सकते है नियंत्रक, उनके आप jsp दृश्य या किसी दृश्य

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

और नियंत्रक में आप कुछ इस तरह जो वसंत नियंत्रण में करने के लिए इच्छित पृष्ठ कारण आपके अनुरोध पर ले जाएगा, क्या करना है प्रदान कर सकते हैं ler दृश्य पृष्ठों के नेविगेशन का निर्णय

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