您的位置:首页 > 其它

Servlet自学第26讲:禁用cookie后还能继续使用session的方法

2015-05-28 19:51 519 查看

把session ID回写到cookie

//cookie名字必须为JSESSION 区分大小写

Cookie cookie = new Cookie("JSESSION",session.getID());
cookie.setMaxAge(60*30);
response.addCookie(cookie);


URL地址重写

//使用一次session 以便获得sessionID
request.getSession();
//编码
String url = response.encodeRedirectURL("/UserManager/BuyBookCL?id=101");
PrintWriter.println("<a href='"+url+"'>加入购物车</a>");
//在返回时也要加入 URL地址重写
String url = response.encodeRedirectURL("/UserManager/ShowBook");
PrintWriter.println("<a href='"+url+"'>返回购买页面</a><br/>");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: