IE禁用Cookie方式:
例一:
demo.do相关代码
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession session=request.getSession();
String jsessionid=session.getId();
Cookie sessionCookie=new Cookie("JSESSIONID", jsessionid);
session.setAttribute("name", "zzz");
String url=response.encodeRedirectURL("./demo2.do");
response.sendRedirect(url);
}
demo2.do相关代码
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession session = request.getSession();
// 获取session的id
String jsessionid = session.getId();
System.out.println(session.getAttribute("name"));
}
输入地址http://127.0.0.1:8080/cookie/demo.do
结果
地址栏结果:
http://127.0.0.1:8080/cookie/demo2.do;jsessionid=D2B0058380743E3731D50C49E6355144
HttpWatch结果:
控制台有输出为zzz
例二:
demo.do代码
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<body>");
//String url=response.encodeURL("./demo2.do");
out.println("<a href='./demo2.do'>加入购物车</a>");
out.println("<body>");
out.println("</html>");
demo1.do 相关不变
结果与例一类似
说明:
(一)、再禁用cookie后 应该采用 ip地址访问 http://172.16.237.247:8080/web_11/goods.do?oper=detailCart
用于对sendRedirect方法后的url地址进行重写。
用于对表单action和超链接的url地址进行重写