在我的系统中,用户登录页面后,我想在没有关闭Internet Explorer的情况下生成新的http会话ID。
我写这样的代码:
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);
}
}
即使我使会话无效,删除cookie,获得新会话,但会话ID仍然相同。我不知道为什么。是否有任何解决方案可以在不关闭Internet Explorer的情况下生成新的会话ID?