我是 servlet 的新手,我对 HttpSession 有疑问,
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// processRequest(request, response);
String name = request.getParameter("Name");
String phone = request.getParameter("Phone");
String dummy = "some";
HttpSession ses = request.getSession();
ses.setAttribute("SesName", name);
ses.setAttribute("SesPhone", phone);
ses.setAttribute("SesName", dummy);
RequestDispatcher rd = request.getRequestDispatcher("./SessionApiImp");
rd.forward(request, response);
}
现在在另一个 servlet 中,
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// processRequest(request, response);
HttpSession sess = request.getSession();
PrintWriter pw = response.getWriter();
pw.println(sess.getAttribute("SesName"));
pw.println(sess.getAttribute("SesPhone"));
}
- 那么分配给这个的值是什么?我试过了,它返回了与假人相关的值。是什么原因?
谢谢,阿尼尔。