request.getContextPath()、request.getRequestURI()、request.getRequestURI()、getServletPath()
来源:互联网 发布:sql cast和convert 编辑:程序博客网 时间:2024/06/11 09:53
区别:
- request.getContextPath():得到项目的名字,即当前应用的根目录。
- request.getRequestURI():返回相对路径
- request.getRequestURL():返回绝对路径
- request.getServletPath():返回Servlet所对应的url-pattern
写一个最简单的Servlet:TestServlet.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String ContextPath = request.getContextPath(); System.out.println("ContextPath........"+ContextPath); String RequestURI = request.getRequestURI(); System.out.println("RequestURI........"+RequestURI); StringBuffer RequestURL = request.getRequestURL(); System.out.println("RequestURL........"+RequestURL); String ServletPath = request.getServletPath(); System.out.println("ServletPath........"+ServletPath); }
web.xml中的配置如下;
<servlet> <servlet-name>TestServlet</servlet-name> <servlet-class>test.TestServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>TestServlet</servlet-name> <url-pattern>/Test/TestServlet</url-pattern> </servlet-mapping>
在地址栏里输入URL为:
http://localhost:8080/testpath/Test/TestServlet
输出结果为:
其中,testpath为项目名。
ContextPath......../testpathRequestURI......../testpath/Test/TestServletRequestURL........http://localhost:8080/testpath/Test/TestServletServletPath......../Test/TestServlet
0 0
- request.getContextPath()、request.getRequestURI()、request.getRequestURI()、getServletPath()
- request.getRequestURI() 、request.getRequestURL() 、request.getContextPath()、request.getServletPath
- request.getRequestURI() 、request.getRequestURL() 、request.getContextPath()、request.getServletPath()区
- request.getContextPath()、request.getServletPath()、request.getRequestURI()、request.getRealPath("/")路径
- request.getContextPath().getRequestURI().getServletPath().getRequestURL().getRealPath() 图解
- Request中getContextPath、getServletPath、getRequestURI、getRealPath
- 学习request获得路径getContextpath, getServletPath,getRequestUri
- request.getRequestURI()、getRequestURL()、getContextPath()、getServletPath()区别
- request.getRequestURI()、getRequestURL()、getContextPath()、getServletPath()区别
- request.getRequestURI()、getRequestURL()、getContextPath()、getServletPath()区别
- request.getRequestURI()、getRequestURL()、getContextPath()、getServletPath()区别
- request.getRequestURI()、getRequestURL()、getContextPath()、getServletPath()、getPathInfo()
- Request中getContextPath、getServletPath、getRequestURI、request.getRealPath的区别
- Request中getContextPath、getServletPath、getRequestURI、request.getRealPath的区别
- Request中getContextPath、getServletPath、getRequestURI、request.getRealPath的区别
- Request中getContextPath、getServletPath、getRequestURI、request.getRealPath的区别
- Request中getContextPath、getServletPath、getRequestURI、request.getRealPath的区别
- Request中getContextPath、getServletPath、getRequestURI、request.getRealPath的区别
- activity 代码中去掉背景
- IntentFilter
- java
- HDU 1421 搬寝室 (线性dp 贪心预处理)
- 网络IO之阻塞、非阻塞、同步、异步总结
- request.getContextPath()、request.getRequestURI()、request.getRequestURI()、getServletPath()
- poj 3138 ACM Team Selection
- java.lang.IllegalStateException: attempt to re-open an already-closed object
- 稠密(dense)并且唯一(unique)的随机(random)数生成
- 知识储备:HTTP协议
- ZOJ 1586
- POJ -2250
- PlaceHolder到底什么
- Java 截取字符串