先申明,我是自己琢磨出来的,不知道对不对!!
但是,我想应该不会有太大的出入的!
getRequestURI()就相当于你在写一个JSP页面的时候会有这样的东西"action='/WebRoot/xxx'"这个方法就是获得'/WebRoot/xxx',也就是说它会得到一个相对地址
而getRequestURL()会得到一个完整的URL地址,也就是绝对的绝对地址
Request.getRequestURL返回的是请求的全部,包括Http协议,端口号,servlet名字和映射路径,但它不包含请求参数。
request.getRequestURI得到的是request URL的部分值,并且web容器没有decode过的
Java code
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->getRequestURL:
public java.lang.StringBuffer getRequestURL()
Reconstructs the URL the client used to make the request. The returned URL contains a protocol, server name, port number, and server path, but it does not include query string parameters.
Because this method returns a StringBuffer, not a string, you can modify the URL easily, for example, to append query parameters.
This method is useful for creating redirect messages and for reporting errors.
Returns:
a StringBuffer object containing the reconstructed URL
getRequestURI:
public java.lang.String getRequestURI()
Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request. The web container does not decode this String. For example:
First line of HTTP request Returned Value
POST /some/path.html HTTP/1.1 /some/path.html
GET http://foo.bar/a.html HTTP/1.0 /a.html
HEAD /xyz?a=b HTTP/1.1 /xyz
To reconstruct an URL with a scheme and host, use HttpUtils.getRequestURL(javax.servlet.http.HttpServletRequest).
Returns:
a String containing the part of the URL from the protocol name up to the query string
See Also:
HttpUtils.getRequestURL(javax.servlet.http.HttpServletRequest)
request.getRequestURI() /jqueryWeb/resources/request.jsp
request.getRequestURL() http://localhost:8080/jqueryWeb/resources/request.jsp
request.getContextPath()/jqueryWeb
request.getServletPath()/resources/request.jsp
注: resources为WebContext下的目录名
jqueryWeb 为工程名
分享到:
相关推荐
HttpServletRequest 中 getRequestURL和getRequestURI的区别文档
// session.setAttribute("redirectUrl", request.getRequestURL().append("?").append(request.getQueryString()).toString()); String url = request.getParameter("url"); URLEncoder.encode(URLDecoder....
String getRequestURI() StringBuffer getRequestURL() String getContextPath() ---web应用的名称 String getQueryString() ---- get提交url地址后的参数字符串 username=zhangsan&password=123 注意:request...
&&request.getRequestURL().indexOf("regist/merchant/acount.jsp")==-1){ response.sendRedirect(request.getContextPath()); }else{ chain.doFilter(request, response); } } web.xml配置: ...
The doFilter method of the Filter is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain. doGet...
StringBuffer url = new StringBuffer(request.getRequestURI()); if(request.getQueryString() != null) { url.append('?'); url.append(request.getQueryString()); } String newUrl = url.toString()....
同样的,另外一个问题:String HttpServletRequest.getRequestURI();和StringBuffer HttpServletRequest.getRequestURL();返回的内容有何不同?为什么会如此?带着这些问题到网上去搜了下,没发现让自己看了明白的...
String urlString = request.getRequestURL().toString(); String queryString = request.getQueryString(); String queryStringEncode = null; String url; if (queryString != null) { queryStringEncode =...
2.3.1 加载和实例化 ................................................................................................................................16 2.3.2 初始化 ........................................
16 2.3.1 加载和实例化 ................................................................................................................................16 2.3.2 初始化 ....................................
jsp探针ceshi.jsp ; charset=gb2312" %> class LfSpy { boolean supportHibernate = false; boolean supportJNDI = false;...boolean supportJavaxSql = false;...private final String linuxParseMacAddress(String ...
+ request.getRequestURL()); // 返回false return false; } // 取到用户信息,放行 // 把用户信息放入Request request.setAttribute("user", user); // 返回值决定handler是否执行。true:执行,false:不...
String uri = httpRequest.getRequestURI();//获取URI String basePath = httpRequest.getContextPath();//获取basePath if(null != uri && uri.startsWith(basePath)){ uri = uri.replace(basePath, ""); } 3...
然而,一个映射可能是由一个URL和许多Servlet实例组成,例如:一个分布式的Servlet引擎可能运行在不止一个的服务器中,这样的话,每一个服务器中都可能有一个Servlet实例,以平衡进程的载入。作为一个Servlet的...
const getRequestUrl = require('ali-cdn-url') const pubArgs = { SignatureVersion: '1.0', Format: 'JSON', Timestamp: '2015-08-06T02:19:46Z', AccessKeyId: 'testid', SignatureMethod: 'HMAC-SHA1', ...