根據request獲取請求路徑

根據request獲取請求路徑:java

下面是一個完成的路徑,包含請求參數web

HttpServletRequest httpRequest=(HttpServletRequest)request;  
          
String strBackUrl = "http://" + request.getServerName() //服務器地址  
                    + ":"   
                    + request.getServerPort()           //端口號  
                    + httpRequest.getContextPath()      //項目名稱  
                    + httpRequest.getServletPath()      //請求頁面或其餘地址  
                + "?" + (httpRequest.getQueryString()); //參數
一、request.getRequestURL()

返回的是完整的url,包括Http協議,端口號,servlet名字和映射路徑,但它不包含請求參數。服務器

二、request.getRequestURI()

獲得的是request URL的部分值,而且web容器沒有decode過的jsp

三、request.getContextPath() 

返回 the context of the request.url

四、request.getServletPath() 

返回調用servlet的部分url.code

五、request.getQueryString() 

返回url路徑後面的查詢字符串字符串

示例:get

當前url:http://localhost:8080/CarsiLogCenter_new/idpstat.jsp?action=idp.sptopnservlet

request.getRequestURL()   http://localhost:8080/CarsiLogCenter_new/idpstat.jsp
request.getRequestURI()   /CarsiLogCenter_new/idpstat.jsp
request.getContextPath()  /CarsiLogCenter_new
request.getServletPath()   /idpstat.jspio

request.getQueryString()  action=idp.sptopn

相關文章
相關標籤/搜索