0

私は3つのjspを持っています、、、、GetAllEmployee今、1つのjspでコーディングEmployeeFindByidする必要があります。ユーザーが新しいポップウィンドウをクリックして開き、クリックした後にIDを要求すると、ホームページ(index.jsp)に3つすべてのボタンを提供しました送信ボタンの出力は、 index.jsp に入力する必要があります。私はm の一部で立ち往生しています。ユーザーがボタンをクリックすると、これらを 1 つの JSP ページに書き込む必要があるため、1 つのポップ ウィンドウを開いて値を取得する必要があります。自動的に閉じます。私は、1 つの jsp のコードの特定のセクションを実行する方法を提供することができません。これは私のサーブレット パッケージです。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