根据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

相关文章
相关标签/搜索