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

Can I access a cookie created by a servlet in a html page?

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

时如何处理会话

您可以使用 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

希望对您有所帮助!