關於request.getRequestURL()和request.getRequestURI

request.getRequestURL()和request.getRequestURI
  如果請求爲:http://localhost:8080/ServletTest02/servlet/Hello01

  request.getRequestURI() 的返回值:/ServletTest02/servlet/Hello01
  request.getRequestURL() 的返回值:http://localhost:8080/ServletTest02/servlet/Hello01

補充下:
  request.getContextPath() = /ServletTest02
  
  request.getLocalAddr() = 127.0.0.1

  request.getScheme() = http

  request.getServerName() = 127.0.0.1

  request.getServletPath() = /servlet/Hello01

  request.getHeaderNames() = org.apache.tomcat.util.http.NamesEnumerator@1fb050c

  request.getLocale() = zh_CN

  request.getLocales() = org.apache.catalina.util.Enumerator@1228a1c

  request.getRealPath("newsPub") =
D:\data\com.genuitec.eclipse.easie.tomcat.myeclipse\tomcat\webapps\ServletTest\newsPub
  
  request.getRealPath("/") =
 D:\data\com.genuitec.eclipse.easie.tomcat.myeclipse\tomcat\webapps\ServletTest02\

http 協議:
uri 表示指定的 URI,要使用涵蓋全部必要信息的絕對 URI、絕對 URL 以及相對 URL。相對 URL,是指從瀏覽器中基本 URI 處指定的 URL,形如 /image/logo.gif。

URI格式由URI協議名(例如http、ftp、mailto、file),一個冒號,和協議對應的內容所構成。

URI的最常見的形式是統一資源定位符(URL)

統一資源定位符(英語:Uniform Resource Locator,縮寫:URL;或稱統一資源定位器、定位地址、URL地址

url 是uri 的子集,uri的形式更多樣化,url 定位資源沒有相對一說。
URL指定要使用的協議類型,而URI不涉及協議規範。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章