Request.getRequestURL


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 為工程名


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM