Session is lost and created as new in every servlet request

前端 未结 9 1406
暖寄归人
暖寄归人 2020-11-28 03:56

I have this big issue. My current session is gone every time I made a new request to Server.

I have checked in a lot of places. I can\'t find what\'s the problem. I

9条回答
  •  攒了一身酷
    2020-11-28 04:59

    After years, I never posted the answer back here. At that time I was busy and forgot about this question. But, today I am looking for a solution in Stackoverflow as usual and saw this notification mentioning I am getting points from this Question. Seems like other developers are facing the same issue. So, I tried to recall how I solved the issue. And yes, I solved by manually put back the session id to track/maintain the session id.

    Please see the code that I manually put back jsessionid inside the servlet.

    HttpSession session = request.getSession();
    if (request.getParameter("JSESSIONID") != null) {
        Cookie userCookie = new Cookie("JSESSIONID", request.getParameter("JSESSIONID"));
        response.addCookie(userCookie);
    } else {
        String sessionId = session.getId();
        Cookie userCookie = new Cookie("JSESSIONID", sessionId);
        response.addCookie(userCookie);
    }
    

提交回复
热议问题