Issue
i have controller through which it navigate to home.jsp
in home .jsp there is two button FindEmployeeByid
FindEmployeeByName
now as i click on FindEmployeeByid new popup window is opened but in pop window i got this message The requested resource (/EmployeeWebSpring/search/Search.jsp) is not available.
,because in Search.jsp i have use form tag of spring so it does not able to get model object so plz tell how i can perform this to open a pop window with input fields active so that i can submit the data a perform some operation on that data
this is my 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;
}
}
this is my 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> </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> </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>
and this is my 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>
Solution
You can do the following in java script and run your java script function as your function run it takes control to controller ,their you can provide the jsp view or any view
<script>
function popup() {
window.open("../popup/searchspring", 'window', 'width=200,height=100');
}
</script>
and in controller you have to do something like this which will navigate your request to desired page cause in spring controller decide the navigation of view pages
@RequestMapping(value = "/searchspring", method = RequestMethod.GET)
public String view(Model model) throws Exception {
EmployeeBO employeeBO = new EmployeeBO();
model.addAttribute("employeeBO", employeeBO);
return "EmployeeForm";
}
Answered By - henrycharles
Answer Checked By - Willingham (JavaFixing Volunteer)