我正在尝试创建一个在所有页面中都需要用户ID的预订表格。当我将页面重定向为[HTML-> servlet-> HTML]
时,我想知道如何处理会话答案 0 :(得分:1)
您可以将 HttpSession.setAttribute 和 HttpSession.getAttribute 用于例如:
JSP页面:
//getting id value
String id= request.getParameter("user_id");
//the variable which is set in session scope you can use anywhere
request.getSession().setAttribute("id",id);
request.getRequestDispatcher("/yourServleturl").forward(request,response);
现在要获得session
属性,如下所示:servlet
:
HttpSession session=request.getSession();
//getting value in session
String id=session.getAttribute("id").toString();
//do further processing
希望这会有所帮助!