【转载】response对象 encodeURL与encodeRedirectURL
来源:互联网 发布:http post web数据 编辑:程序博客网 时间:2024/06/04 17:47
转载地址:http://blog.sina.com.cn/s/blog_4cc16fc50100bxt9.html
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.
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 separete from the encodeURL method.
两种情况会用到引用自身站点的URL
第一种,在servlet生成的 web页面中含有嵌入的URL,应该将这URL传递给 response的 encodeURL()。这个方法确定当前是否在使用URL重写,仅在必需时附加会话信息;否则不做更改直接返回传入的URL:
String aURL = someURL;
String encodeUrl = response.encodeURL(aURL);
out.print(“< A href=” + encodeUrl ….);
第二种情况是在sendRedirect()调用中(即放入Location响应报头)。这种情况下,由于要根据不同规则确定是否需要附加会话信息,因而不能使用encodeURL,需要使用HttpServletResponse的 encodeRedirectURL()。
String originalURL = someURL;
String encodeUrl = response.encodeRedirectURL(originalURL);
response.sendRedirect(encodeUrl);
如果认为自己的Web应用最终有可能使用URL重写来替代Cookie,那么最好预先规划,对引用自身站点的URL进行编码。
- 【转载】response对象 encodeURL与encodeRedirectURL
- response encodeRedirectURL encodeURL作用
- response encodeRedirectURL encodeURL作用
- response.encodeURL or encodeRedirectURL and jsessionid
- response encodeRedirectURL encodeURL作用(转)
- HttpServletResponse的encodeRedirectURL()与encodeURL()的差别
- Response对象的encodeURL原理
- response.encodeRedirectURL
- 关于request的getSession()、response的encodeRedirectURL(String url) 和encodeURL(String url)
- 通俗理解encodeURL() 和 encodeRedirectURL()
- response.encodeurl
- response.encodeRedirectURL作用
- response.encodeURL的使用
- response.encodeURL的用法
- response.encodeURL的用法
- response.encodeURL的用法
- response.encodeURL 详解
- response.encodeURL的用法
- Docker学习总结之Run命令介绍
- 如何判断自己是否具有成为一名优秀程序员的潜质及如何成为一名优秀的程序员
- static和全局变量和局部变量的问题
- Spring 4.2.4.RELEASE MVC 学习笔记 - 7 - RestFull API(咋个办呢 zgbn)
- 【手把手教你全文检索】Apache Lucene初探
- 【转载】response对象 encodeURL与encodeRedirectURL
- php-fpm进程数优化方法
- nginx 反向代理和正向代理区别
- Java 线程面试问题
- 【PHP学习】move_uploaded_file的使用
- 包管理工具之npm 和bower
- Android kernel log获取
- WindowManager 和Dialog提升Windowtype等级
- ARM简介