http://www.cnblogs.com/zxp_9527/archive/2009/05/07/1452253.html
来源:互联网 发布:linux关闭selinux 编辑:程序博客网 时间:2024/04/28 17:42
原文网址:http://www.cnblogs.com/zxp_9527/archive/2009/05/07/1452253.html
当用URL-rewriting方式来管理Session的时候,通过以上两个方法把session ID写到URL中。
不同点是:两个方法确定是否需要包含session ID的逻辑不同。在调用HttpServletResponse.sendRedirect前,应该先调用encodeRedirectURL()方法,否则可能会丢失Sesssion信息。
在使用URL重写几只的时候要注意,为了保证会话跟踪的正确性,所有的链接和重定向语句中的URL都需要调用encodeURL()或encodeRedirectURL()方法进行编码。另外,由于附加在URL中的session ID是动态产生的,对每一个用户是不同的,所以对于静态页面的相互跳转,URL重写机制无能为力。当然可以通过将静态页面转换为动态页面解决。
方法的执行:首先判断当前的Servlet是否执行了HttpSession对象的invalidate()方法,如果已经执行返回参数URL。接下来判断客户端是否禁用了Cookie,没有禁用直接返回参数URL,如果禁用,则在参数URL中附加session ID,返回编码后的URL。
摘一段API中的描述:
public java.lang.String encodeURL(java.lang.String url)
Encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged. The implementation of this method includes the logic to determine whether the session ID needs to be encoded in the URL. For example, if the browser supports cookies, or session tracking is turned off, URL encoding is unnecessary.
For robust session tracking, all URLs emitted by a servlet should be run through this method. Otherwise, URL rewriting cannot be used with browsers which do not support cookies.
public java.lang.String encodeRedirectURL(java.lang.String url)
Encodes the specified URL for use in the sendRedirect method or, if encoding is not needed, returns the URL unchanged. The implementation of this method includes the logic to determine whether the session ID needs to be encoded in the URL. Because the rules for making this determination can differ from those used to decide whether to encode a normal link, this method is separated from the encodeURL method.
All URLs sent to the HttpServletResponse.sendRedirect method should be run through this method. Otherwise, URL rewriting cannot be used with browsers which do not support cookies.
具体的区别有时间去深究java源代码!!!
- http://www.cnblogs.com/zxp_9527/archive/2009/05/07/1452253.html
- Chart Controls (http://www.cnblogs.com/peterzb/archive/2009/07/21/1528246.html)
- http://www.cnblogs.com/yungboy/archive/2009/07/26/1531422.html
- http://www.cnblogs.com/dubingsky/archive/2009/07/16/1524742.html
- http://www.cnblogs.com/peterzb/archive/2009/07/19/1526555.html
- jQuery Ajax 实例 全解析http://www.cnblogs.com/yeer/archive/2009/07/23/1529460.html
- JavaScript继承详解(五)http://www.cnblogs.com/sanshi/archive/2009/07/14/1523523.html
- http://www.cnblogs.com/tekson/archive/2009/07/16/1524604.html
- http://www.cnblogs.com/wangkewei/archive/2009/05/20/1472629.html
- http://www.cnblogs.com/lsxqw2004/archive/2009/05/31/1495240.html
- C#位运算 http://www.cnblogs.com/sweting/archive/2009/11/05/1596873.html
- Ubuntu--字体设置(http://www.cnblogs.com/top5/archive/2009/11/05/1596919.html)
- http://www.cnblogs.com/Ewin/archive/2009/10/05/1578322.html
- 在IIS上启用Gzip压缩(HTTP压缩) 轉(http://www.cnblogs.com/zhangziqiu/archive/2009/05/17/gzip.html)
- http文件头详解http://www.cnblogs.com/tiwlin/archive/2009/09/06/1561279.html
- 使用SqlDataAdapter对象获取数据(转自:http://www.cnblogs.com/zyh-nhy/archive/2009/01/07/1371177.html)
- JAVA UUID 生成 - jdonson - 博客园 http://www.cnblogs.com/jdonson/archive/2009/07/22/1528466.html
- Visual Studio 2008 单元测试(转自:http://www.cnblogs.com/TerryFeng/archive/2009/05/24/1488333.html)
- JS 数字相加
- android (9)
- 斐波那契数列
- 集成电路 RTL 设计
- 如何为外部程序调用时,可传入参数?如何调试?
- http://www.cnblogs.com/zxp_9527/archive/2009/05/07/1452253.html
- atl-ActiveX-dll-inf-cab-web调用(总结篇)
- 巧用搜索语法搜索外文文献
- 最长回文子串
- web高性能开发系列随笔
- 解决"error C4430: missing type specifier - int assumed. Note: C++ does not support default-int"
- EnterpriseLibrary企业库中数据库封装
- Oracle诊断案例-Sql_trace
- 用ado连接oracle的几种方法