http://www.cnblogs.com/zxp_9527/archive/2009/05/07/1452253.html
2011-07-18 15:30
399 查看
原文网址:/article/7107779.html
encodeURL() vs encodeRedirectURL() 当用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源代码!!!
encodeURL() vs encodeRedirectURL() 当用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/perfectdesign/archive/2008/08/11/sql-server-2008-table-valued-parameters.html)
- http://www.cnblogs.com/itnongmin/archive/2011/12/01/2271170.html取值哦,很难得
- Unity3D界面功能操作讲解【转http://www.cnblogs.com/fortomorrow/archive/2012/10/28/unity01.html】
- 函数调用分析 http://www.cnblogs.com/bangerlee/archive/2012/05/22/2508772.html
- http://www.cnblogs.com/wengyuli/archive/2010/06/29/silverlight-video-chat.html
- MySQL 请选择合适的列! 转载(http://www.cnblogs.com/baochuan/archive/2012/05/23/2513224.html)
- http://www.cnblogs.com/yungboy/archive/2010/05/25/1743991.html
- http://www.cnblogs.com/ILove/archive/2008/04/07/1140419.html
- http://www.cnblogs.com/yaozhenfa/archive/2015/06/14/4574898.html
- 异或转载http://www.cnblogs.com/this-543273659/archive/2011/08/30/2159819.html
- 常用EXE文件反编译工具(转http://www.cnblogs.com/ejiyuan/archive/2009/09/08/1562624.html)
- DataGrid资料(转贴 http://www.cnblogs.com/icesnaker/archive/2004/07/31/29017.html)
- 从2-3-4树谈到Red-Black Tree(红黑树) http://www.cnblogs.com/guoyiqi/archive/2011/06/08/2129310.html
- MySQL 插入数据时,中文乱码问题的解决http://www.cnblogs.com/sunzn/archive/2013/03/14/2960248.html
- http://www.cnblogs.com/haojianwei/archive/2010/03/02/1676707.html
- ASP.NET生成静态页 (http://www.cnblogs.com/xlovey/archive/2007/11/16/961092.html)
- AJAX从服务端获取数据的三种方法【转:http://www.cnblogs.com/nokiaguy/archive/2008/05/25/1207157.html】
- static作用(修饰函数、局部变量、全局变量)转自http://www.cnblogs.com/stoneJin/archive/2011/09/21/2183313.html
- 如何計算浮點數? (SOC) (Verilog) http://www.cnblogs.com/oomusou/archive/2008/10/11/verilog_floating.html
- sql把逗号分隔的字符串拆成临时表(转:http://www.cnblogs.com/eleven11/archive/2010/08/17/1800901.html)