会话无效后,是否可以通过request.getSession()通过请求对象获得新会话而无需发出新请求?
我的请求对象流到第一页到第二页,第二页又到第一页,第一页到第二页,再到第二页到第二页....请求页不能更改,但是每次请求第一页到第二页时我们需要获取详细信息进行会话并使它无效,然后再次创建它。
HttpSession session = request.getsession(false)
String user = (String)session.getAttribute("name");
session.invalidate();
session=request.getSession(true);
RequestDispacher dis = request.requestDispatcher("path");
dis.forword(request,respone);
Run Code Online (Sandbox Code Playgroud)
但这在第二次上不起作用,它提供了空会话或详细信息
也尝试像这样在即将到来的cookie中设置会话ID
Cookie[] c = request.getCookies();
for(Cookie k: c){
if(k.getName().equalsIgnoreCase("JSESSIONID")){
System.out.println("k.getValue() : "+k.getValue());
System.out.println("httpSession.getId() : "+httpSession.getId());
k.setValue(httpSession.getId());
}
}
Run Code Online (Sandbox Code Playgroud)