客户端禁用cookie后如何继续使用session追踪?
服务器端获取Session对象依赖于客户端携带的Cookie中的JSESSIONID数据。如果用户把浏览器的隐私级别调到最高,这时浏览器是不会接受Cookie、这样导致永远在服务器端都拿不到的JSESSIONID信息。这样就导致服务器端的Session使用不了。
Java针对Cookie禁用,给出了解决方案,依然可以保证JSESSIONID的传输。
Java中给出了再所有的路径的后面拼接JSESSIONID信息。 对URL重写
针对超链接和表单 response#encodeURL(String url)
针对重定向 response#encodeRedirectURL(String url)
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
HttpSession session = request.getSession();
session.setAttribute("name","88");
String path="/cs/servlet2";
System.out.println(path);
path= response.encodeRedirectURL(path);
System.out.println(path);
response.sendRedirect(path);
return;
}