我会尽力解释。
我有一个 doPost 可以返回特定部门的所有员工。
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = null;
Connection conn = null;
Statement stmt = null;
ResultSet res = null;
String department = request.getParameter("department");
try
{
response.setContentType("text/html");
out = response.getWriter();
out.println("<BODY>");
out.println("<TABLE BORDER=1>");
out.println("<TR>");
out.println("<TD>Id</TD>");
out.println("<TD>Name</TD>");
conn = ConnectionManager.getConnection();
stmt = conn.createStatement();
res = stmt.executeQuery("select * from employees where department ='" + request.getParameter("department") + "'");
if(department.isEmpty())
{
String message = "Employee Name Invalid";
request.setAttribute("message", message);
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/test.jsp");
dispatcher.forward(request, response);
}
if (department.matches(department))
{
while(res.next())
{
out.println("<TR>");
out.println("<TD>" + res.getString(1) + "</TD>");
out.println("<TD><a href='employeeDetail.jsp'>"+ res.getString(3) + " " + res.getString(2) +"</a></TD>");
HttpSession session = request.getSession();
session.setAttribute("name", res.getString(3));
session.setAttribute("lname", res.getString(2));
session.setAttribute("id", res.getString(1));
session.setAttribute("dob", res.getString(6));
session.setAttribute("address", res.getString(8));
session.setAttribute("city", res.getString(9));
session.setAttribute("state", res.getString(10));
session.setAttribute("zip", res.getString(11));
session.setAttribute("phone", res.getString(13));
session.setAttribute("hd", res.getString(7));
session.setAttribute("ext", res.getString(14));
session.setAttribute("dept", res.getString(18));
session.setAttribute("notes", res.getString(16));
}
}
out.println("</TABLE>");
out.println("</BODY>");
}
catch (Exception e)
{
throw new ServletException(e.toString());
}
选择销售部门后,结果为:
标识名称
1 南希 D ..... 2 安德鲁 F ..... 3 珍妮特 L .....
每个名称都超链接到一个employeeDetail.jsp。由于某种原因,它没有显示在上面的列表中。
当我单击任何链接(南希、安德鲁、珍妮特)时,我只会得到最后一个元素(珍妮特)的结果。
我的问题是如何获取我点击的员工的具体详细信息?
我试过查找这个,但我认为我没有正确地问这个问题。
此外,我将不胜感激任何关于我可以对我的 servlet 进行更改的指针。
谢谢。