2013-01-11 183 views
0

我的要求是我想要在父JSP或其他jsp上填充數據,或者在使用spring彈出時關閉其他jsp。我面臨的問題無法打開彈出窗口,但提交後的數據價值數據填充相同的彈出我想要在不同的頁面,例如我做了彈出窗口打開我已經提交'Employee_Id'數據的值數據填充上彈出本身我不知道如何來填充使用這裏的春天不同的頁面上的數據是我的代碼使用彈簧在彈出窗口中提交數據後在父窗口或其他窗口填充數據

這是我的控制器

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.bind.annotation.RequestParam; 
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() throws Exception { 
     return "Home"; 
    } 

    @RequestMapping(value = "/searchPage", method = RequestMethod.GET) 
    public ModelAndView search(@Validated EmployeeForm employeeForm, 
      @RequestParam("selectedValue") String selectedValue) 
      throws Exception { 
     ModelAndView model = new ModelAndView(); 

     if (selectedValue.equals("FindEmployeeById")) { 
      boolean x = true; 
      model.addObject("x", x); 
     } 
     if (selectedValue.equals("FindEmployeeByName")) { 

      boolean y = true; 
      model.addObject("y", y); 

     } 

     if (selectedValue.equals("FindByDepartmentId")) { 
      boolean z = true; 
      model.addObject("z", z); 
     } 
     model.setViewName("Search"); 
     return model; 
    } 

    @RequestMapping(value = "/FindById", method = RequestMethod.GET) 
    public ModelAndView searchByEmpNo(
      @ModelAttribute("employeeForm") EmployeeForm employeeForm) 
      throws Exception { 
     ModelAndView model = new ModelAndView(); 
     model.addObject("employeeForm", employeeForm); 
     Integer i = (employeeForm.getEmployeeNumber()); 

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

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

    @RequestMapping(value = "/FindByName", 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.addObject("block", "block"); 
     model.setViewName("EmployeeList"); 
     return model; 

    } 

,這是我的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> 
<script type="text/javascript"> 
    function doAllThese(url) { 

     if (url == 'FindById') { 
      document.form.action = "/EmployeeWebSpring/search/FindById"; 

     } 
     if (url == 'FindByName') { 
      document.form.action = "/EmployeeWebSpring/search/FindByName"; 
     } 
     if (url == 'FindByDeptNO') { 
      document.form.action = "/EmployeeWebSpring/search/FindByDeptNO"; 
     } 
    } 
    function loadName(name) { 

     this.firstName = name; 
     window.location = 'http://localhost:8080/EmployeeWeb/GetEmployee?key1=' 
       + encodeURIComponent(firstName); 

    } 
</script> 
</head> 
<body> 
    <form:form name="form" commandName="employeeForm" method="post"> 



     <c:if test="${requestScope.x}"> 
      <div id="div1"> 
       Employee_ID: 
       <form:input path="employeeNumber" /> 
       <input type="submit" name="method" value="FindById" id="FindById" 
        onclick="doAllThese(this.value)" /> 
      </div> 
     </c:if> 
     <c:if test="${requestScope.y}"> 

      <div id="div2" > 

       Employee_Name 
       <form:input path="firstName" /> 
       <input type="submit" name="method" value="FindByName" 
        onclick="doAllThese(this.value)" /> <br /> <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> 
      </div> 
     </c:if> 
     <c:if test="${requestScope.z}"> 
      <div id="div3"> 
       Employee_Name 
       <form:input path="departmentId" /> 
       <input type="submit" name="method" value="FindByDeptNO" 
        onclick="doAllThese(this.value)" /> 
      </div> 
     </c:if> 
    </form:form> 
</body> 
</html> 

和這是我在使用中的ds-servlet xml ternal視圖解析器

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
          http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
          http://www.springframework.org/schema/context 
          http://www.springframework.org/schema/context/spring-context-3.2.xsd 
          http://www.springframework.org/schema/mvc 
          http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"> 

    <context:annotation-config /> 

    <mvc:annotation-driven /> 

    <bean class="org.springframework.jdbc.datasource.DriverManagerDataSource" 
     id="dataSource"> 
     <property value="com.mysql.jdbc.Driver" name="driverClassName" /> 
     <property value="jdbc:mysql://192.168.25.30:3306/employee" 
      name="url" /> 
     <property value="hr" name="username" /> 
     <property value="hr123" name="password" /> 
    </bean> 
    <bean id="employeeDaoImpl" class="com.nousinfo.tutorial.employee.dao.impl.EmployeeDAOImpl"> 
     <property name="dataSource" ref="dataSource" /> 
    </bean> 

    <bean id="employeserviceImpl" class=" com.nousinfo.tutorial.service.impl.EmployeeServiceImpl"> 
     <property name="daoImpl" ref="employeeDaoImpl" /> 
    </bean> 

    <bean id="mycontroller" 
     class="com.nousinfo.tutorial.controllers.SearchEmployeeController"> 
     <property name="employeeServiceImpl" ref="employeserviceImpl"></property> 
    </bean> 
    <bean id="emplController" class="com.nousinfo.tutorial.controllers.EmployeeController"> 
     <property name="employeeServiceImpl" ref="employeserviceImpl"></property> 
    </bean> 



    <bean id="configurationLoader" 
     class="org.springmodules.validation.bean.conf.loader.annotation.AnnotationBeanValidationConfigurationLoader" /> 
    <bean id="validator" class="org.springmodules.validation.bean.BeanValidator" 
     p:configurationLoader-ref="configurationLoader" /> 

    <bean id="viewResolver" 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
     p:prefix="/WEB-INF/" p:suffix=".jsp" /> 

    <bean id="messageSource" 
     class="org.springframework.context.support.ResourceBundleMessageSource"> 
     <property name="basename" value="com/nousinfo/resources/messages" /> 
    </bean> 
    <!-- Configure the multipart resolver --> 
    <bean id="multipartResolver" 
     class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> 
    </bean> 

回答

0

關閉我的頭頂,您有以下選項:

  1. 提交彈出的,存儲在會話的relavent更新的數據或其他地方,你可以得到它,然後使用JS在父頁面調用重新加載
  2. 進行父表AJAX的加載,然後在彈出窗口關閉後,調用AJAX代碼以重新加載頁面的內容。
  3. 拿出一些非常複雜的JS使用在彈出的數據更新父頁...我認爲這不是一個很好的解決方案

的Spring MVC是一個服務器端工具,這意味着所有的數據正在服務器端進行處理。如果您想直接使用Spring獲取任何新數據,您需要以某種方式撥打服務器電話。

相關問題