0

我有三个 jsp,,,,GetAllEmployee现在我必须在一个 jsp 中编写代码,EmployeeFindByid当用户单击新的弹出窗口打开并在单击后要求 id提交按钮输出应该填充在 index.jsp 中我已经完成了m 卡在部分中,因为当用户单击按钮时,我必须将这些写在一个 jsp 页面中,应该打开一个弹出窗口并取值然后弹出窗口应该会自动关闭。我无法提供如何执行一个 jsp 的特定代码部分的条件,这是我的 servlet 包;EmployeeFindByNameEmployeeFindByIdEmployeeFindByNameemployeeFindbyidGetAllEmployeeiEmployeeFindByidEmployeeFindByNamecom.nousinfo.tutorial

import java.io.IOException;

import java.io.PrintWriter;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.nousinfo.tutorial.employee.service.model.bo.EmployeeBO;
import com.nousinfo.tutorial.service.bo.EmployeeService;
import com.nousinfo.tutorial.service.bo.impl.EmployeeServiceImpl;
import com.nousinfo.tutorial.service.exception.EmployeeServiceBOException;
import com.nousinfo.tutorial.service.exception.EmployeeServiceException;

/**
 * Servlet implementation class GetEmployee
 */
public class GetEmployee extends HttpServlet {
    private static final long serialVersionUID = 1L;
    EmployeeService employeeService = new EmployeeServiceImpl();

    /**
     * @see HttpServlet#HttpServlet()
     */
    public GetEmployee() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void service(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        String name = request.getParameter("findbyid");
        System.out.println(name);
        RequestDispatcher dispatcher = null;
        try {

            if (request.getParameter("findbyid") != null) {

                request.setAttribute("EmployeeObject", findEmployees(Long
                        .parseLong(request.getParameter("findbyid"))));
                dispatcher = request.getRequestDispatcher("/jsp/employee.jsp");

            } else {
                request.setAttribute("employeeList", getAllEmployee());
                dispatcher = request.getRequestDispatcher("/jsp/winopen.jsp");
            }
            if (dispatcher != null)
                dispatcher.forward(request, response);

        } catch (EmployeeServiceBOException e) {
            e.printStackTrace();
        }
    }

    private List<EmployeeBO> getAllEmployee() throws EmployeeServiceBOException {
        return employeeService.getAllEmployees();
    }

    private EmployeeBO findEmployees(long id) throws EmployeeServiceBOException {

        return employeeService.getEmployee(id);
    }

    private List<EmployeeBO> findEmployees(String name)
            throws EmployeeServiceBOException {

        return employeeService.findEmployees(name);
    }
}

这是我的 index.jsp

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!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><title>Home</title>
</head>
<body>
<table width="951" height="116" border="0" align="center">
  <tr>
    <td width="661" height="112" align="center" bgcolor="#99CCFF"><h2>Project Management </h2></td>
    <td width="266" height="112" align="center" bgcolor="#FFFFFF"><img src="../image/nous.jpg" alt="1" width="266" height="84" /></td>
  </tr>
</table>
<p>&nbsp;</p>


    <table width="949" height="183" border="0" align="center">

      <tr>
        <td height="42" align="center" bgcolor="#3366FF"><strong>Find Employee </strong></td>
      </tr>

  <tr>

    <td height="43"><form id="form2"  method="post" action="/EmployeeWeb/GetEmployee">

       <input name="Submit2" type="submit" class="button" value="GetAllEmployee"/>

    </form>    </td>
  </tr>

<tr>
<td width="943" height="43">
<input name="Submit" type="submit" value="getEmployee By ID"
onClick="window.open('file.jsp','mywindow','width=500,height=200 align=center,toolbar=no,resizable=yes,menubar=yes' )" />
</td>
</tr>

    <tr>
    <td height="43">
    <input name="Submit2" type="submit" class="button" value="Get Employee By Name"  onClick="window.open('winopen.jsp','mywindow','width=500,height=350,toolbar=no,resizable=yes,menubar=yes')"/>
     </td>
  </tr>
</table>

<p>&nbsp;</p>
</body>
</html>

这是我的 getAllEmployee.jsp

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!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">
<title>Insert title here</title>
</head>
<body>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@page  language="java" import="com.nousinfo.tutorial.employee.service.model.bo.*" %>
<%@page  language="java" import="java.util.*" %>
 <input name="employee id" value="">

    <table >
        <tr>
            <th>EmployeeNumber</th>
            <th>FirstName</th>
            <th>LastName</th>
            <th>Title</th>
            <th>Address-1</th>
            <th>Address-2</th>
            <th>City</th>
            <th>State</th>
            <th>Pincode</th>
            <th>Mobile_Number</th>
            <th>Date_Of_Birth</th>

        </tr>
    <c:forEach var="employee" items="${employeeList}">
            <tr>
                <td>${employee.empNumber}</td>
                <td>${employee.firstName}</td>
                <td>${employee.lastName}</td>
                <td>${employee.title}</td>
                <td>${employee.address1}</td>
                <td>${employee.address2}</td>
                <td>${employee.city}</td>
                <td>${employee.state}</td>
                <td>${employee.pincode}</td>
                <td>${employee.mobileNUmber}</td>
                <td>${employee.dateOfBirth}</td>

            </tr>
        </c:forEach>
    </table>

</body>
</html>
4

0 回答 0