request获得路径相关大全

request.getURL()和request.getURI()

  如果我的请求是:http://localhost:8080/ServletTest/servlet/Hello

  request.getRequestURI() 返回值类似:/ServletTest/servlet/Hello

  request.getRequestURL() 返回值类似:http://localhost:8080/ServletTest/servlet/Hello

  再如:

  request.getContextPath() = /ServletTest

  request.getLocalAddr() = 127.0.0.1

  request.getPathInfo() = null

  request.getPathTranslated() = null

  request.getRemoteAddr() = 127.0.0.1

  request.getRequestURI() = /ServletTest/servlet/Hello

  request.getScheme() = http

  request.getServerName() = 127.0.0.1

  request.getServletPath() = /servlet/Hello

  request.getClass() = class ornnector.RequestFacade

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

  request.getLocale() = zh_CN

  request.getLocales() = org.apache.catalina.util.Enumerator@1088a1b

  request.getParameterMap() = {}

  request.getRequestURL() =

  request.getUserPrincipal() = null

  request.getParameterNames() = java.util.Hashtable$EmptyEnumerator@1db6942

  request.getRealPath("newsPub") =

  D:\zfsca\.metadata\.plugins\com.genuitec.eclipse.easie.tomcat.myeclipse\tomcat\webapps\ServletTest\newsPub

  request.getRealPath("/") =

  D:\zfsca\.metadata\.plugins\com.genuitec.eclipse.easie.tomcat.myeclipse\tomcat\webapps\ServletTest\


在servlet请求中,使用request获取整个请求url:

String url="http://" + request.getServerName() //服务器地址    
        + ":"     
        + request.getServerPort()           //端口号    
        + request.getRequestURI();    

String queryurl=httprequest.getQueryString();  
    if(null!=queryurl){  
        url+="?"+queryurl;  
    }  
这样获取到的就是整个请求的url

你可能感兴趣的:(技术,request获取路径)