request.getRequestURI()、getRequestURL()、getContextPath()、getServletPath()、getPathInfo()
来源:互联网 发布:淘宝宝贝上架技巧 编辑:程序博客网 时间:2024/06/04 01:30
request.getRequestURI() /jqueryWeb/resources/request.jsp
request.getRequestURL() http://localhost:8080/jqueryWeb/resources/request.jsp
request.getContextPath() /jqueryWeb
request.getServletPath() /resources/request.jsp
request.getPathInfo()
1. 如果我们的 servlet-mapping 如下配置:
<servlet-mapping> <servlet-name>jetbrick-template</servlet-name> <url-pattern>*.jetx</url-pattern></servlet-mapping>
那么访问: /context/templates/index.jetx
request.getServletPath() == "/templates/index.jetx"request.getPathInfo() == <null>
2. 如果我们的 servlet-mapping 如下配置:
<servlet-mapping> <servlet-name>jetbrick-template</servlet-name> <url-pattern>/*</url-pattern></servlet-mapping>
那么访问: /context/templates/index.jetx request.getServletPath() == ""request.getPathInfo() == "/templates/index.jetx"
3. 如果我们的 servlet-mapping 如下配置:
<servlet-mapping> <servlet-name>jetbrick-template</servlet-name> <url-pattern>/template/*</url-pattern></servlet-mapping>
那么访问: /context/templates/index.jetx
request.getServletPath() == "/templates"request.getPathInfo() == "/index.jetx"
总结 :
所以,我们要获取相对于 request.getContextPath() 的路径,我们可以使用如下的代码:
String uri = request.getServletPath();String pathInfo = request.getPathInfo();if (pathInfo != null && pathInfo.length() > 0) { uri = uri + pathInfo;}
或者:
String uri = request.getRequestURI();String contextPath = request.getContextPath();if (contextPath != null && contextPath.length() > 0) { uri = uri.substring(contextPath.length());}
参考:
http://blog.csdn.net/z507263441/article/details/44171815
https://my.oschina.net/sub/blog/182408
阅读全文
0 0
- request.getRequestURI()、getRequestURL()、getContextPath()、getServletPath()、getPathInfo()
- getPathInfo() getServletPath() getContextPath() getRequestURL() getRequestURI()
- request.getContextPath().getRequestURI().getServletPath().getRequestURL().getRealPath() 图解
- request.getRequestURI()、getRequestURL()、getContextPath()、getServletPath()区别
- request.getRequestURI()、getRequestURL()、getContextPath()、getServletPath()区别
- request.getRequestURI()、getRequestURL()、getContextPath()、getServletPath()区别
- request.getRequestURI()、getRequestURL()、getContextPath()、getServletPath()区别
- request.getRequestURI() 、request.getRequestURL() 、request.getContextPath()、request.getServletPath
- request.getRequestURI() 、request.getRequestURL() 、request.getContextPath()、request.getServletPath()区
- Request中getContextPath、getServletPath、getRequestURI、getRequestURL、getRealPath的区别
- Request中getContextPath、getServletPath、getRequestURI、getRequestURL、getRealPath的区别
- Request中getContextPath、getServletPath、getRequestURI、getRequestURL、getRealPath的区别
- Request中getContextPath、getServletPath、getRequestURI、getRequestURL、getRealPath的区别
- JavaWEB中request.getRequestURI()、getRequestURL()、getContextPath()、getServletPath()区别
- request.getContextPath()、request.getRequestURI()、request.getRequestURI()、getServletPath()
- getContextPath、getServletPath、getRequestURI、getRealPath、getRequestURL、的区别
- getRequestURL、getRequestURI、getContextPath、getServletPath和getRealPath的区别
- Request中getContextPath、getServletPath、getRequestURI、getRealPath
- Android中adb命令的使用
- oracle dblink mysql
- Xcode运行编译速度慢的两个解决办法
- ZigBee3.0_JENNIC-JN516x-ZigBeeBaseDevice_20170609_1.3
- 分针网—每日分享:代码如何看起来干净
- request.getRequestURI()、getRequestURL()、getContextPath()、getServletPath()、getPathInfo()
- svn: E210004: Number is larger than maximum 解决方案
- MATLAB中改变彩色图像的尺寸大小
- 单链表的结构及其操作
- 交叉编译
- 黑客当勇于自黑
- 高效工作~高效写码~
- mybatis-查询(自动封装得resultType)-12
- ICU资源编译