重新打开浏览器后无法识别JSESSIONID

时间:2018-11-02 19:07:42

标签: java servlets httpsession jsessionid

假设您有两个servlet:

login.java (创建一个新会话并显示JSESSIONID)

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();

    try{
        HttpSession s = request.getSession();
        out.print(s.getId());
    }
    finally{
        out.close();
    }
}

session.java (仅在用户通过身份验证时打印内容)

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    HttpSession s = request.getSession(false);
    if(s == null){
        response.sendError(401);
    }else{
       try{
           out.print("Welcome back, ID" + s.getId());
       }
       finally{
           out.close();
       }
    }
}

如果我先运行登录名然后进行会话(但我不关闭浏览器),一切都很好。 如果我第一次运行登录名,那么我关闭浏览器并重新打开它并输入: http:\ localhost:8080 \ ApplicationName \ session; JSESSIONID = 登录记录的主题 我收到401错误。(我已经在禁用cookie的情况下完成了这些测试!)即使过期时间为30分钟,httpsession是否也已过期?

0 个答案:

没有答案
相关问题