我可以在 html 页面中访问由 servlet 创建的 cookie 吗?

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



德玛西亚99
浏览 71回答 1
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希望这可以帮助 !
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java