开发者

how to generate a new http session id without close internet explorer in Servlet

开发者 https://www.devze.com 2023-02-13 05:11 出处:网络
In my system, 开发者_如何转开发after user login the page, I want to generate a new http session id without close internet explorer.

In my system, 开发者_如何转开发after user login the page, I want to generate a new http session id without close internet explorer.

I write the code like this:

public void doGet(HttpServletRequest request,
                  HttpServletResponse response)
    throws IOException, ServletException
{


    HttpSession session = request.getSession(true);
    System.out.println("session id:"+session.getId());



    session.invalidate();

    deleteCookie( request.getCookies(),request,response);

    session = request.getSession();

    System.out.println("new session id:"+session.getId());

} 

private void deleteCookie(Cookie[] cookies,HttpServletRequest req,HttpServletResponse response){
    logger.debug("Delete cookie");


    int cookieLenght = cookies.length;
    for (int i = 0; i < cookieLenght; i++) {
        Cookie cookie = cookies[i];
        cookie.setMaxAge(0);
        cookie.setPath("/");

        response.addCookie(cookie);

    }

 }

Even I invalidate the session , delete the cookie ,get a new session, but the session Id is still the same. I do not know why. Is there any solution to generate a new session id without close the internet Explorer?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号