我正在尝试创建一个需要所有页面中的用户 ID 的预订表格。我想知道当我将页面重定向为 [HTML->servlet->HTML] 时如何处理会话
1 回答

慕仙森
TA贡献1827条经验 获得超8个赞
您可以使用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
希望这可以帮助 !
添加回答
举报
0/150
提交
取消