request.getRequestURI() /jqueryWeb/resources/request.jsp
request.getRequestURL() http://localhost:8080/jqueryWeb/resources/request.jsp
request.getContextPath()/jqueryWeb
request.getServletPath()/resources/request.jsp

注: resources为WebContext下的目录名
jqueryWeb 为工程名

-----------------------------------------------------
<%=request.getRequestURI() %><br/>
<%=request.getRequestURL() %><br/>
<%=request.getContextPath()%><br/>
<%=request.getServletPath() %><br/>
<%=request.getPathInfo() %><br/>
结果:
/test-struts.jsp
http://127.0.0.1:8080/test-struts.jsp

/test-struts.jsp
null

配置:
<action name="test" class="testStrutsAction" method="test"> 
   <result>/test-struts.jsp</result>
</action>

假定你的web application 名称为news,你在浏览器中输入请求路径:

http://localhost:8080/news/main/list.jsp

则执行下面向行代码后打印出如下结果:

1、 System.out.println(request.getContextPath());

打印结果:/news

2、System.out.println(request.getServletPath());

打印结果:/main/list.JSP

3、 System.out.println(request.getRequestURI());

打印结果:/news/main/list.JSp

4、 System.out.println(request.getRealPath("/"));

打印结果:F:\tomcat 6.0\webapps\news\test

request.getRequestURI() 、request.getRequestURL() 、request.getContextPath()、request.getServletPath()区别的更多相关文章

  1. getContextPath、getServletPath、getRequestURI、request.getRealPath的区别

    1 区别 假定你的web application 名称为news,你在浏览器中输入请求路径: http://localhost:8080/news/main/list.jsp 1.1 System.o ...

  2. Request中getContextPath、getServletPath、getRequestURI、request.getRealPath的区别

    1 区别 假定你的web application 名称为news,你在浏览器中输入请求路径: http://localhost:8080/news/main/list.jsp 1.1 System.o ...

  3. request.getRequestURL()和request.getRequestURI()的区别

    request.getRequestURL() 返回全路径 request.getRequestURI() 返回除去host(域名或者ip)部分的路径 request.getContextPath() ...

  4. request.getRequestURI()与request.getRequestURL()

    request.getRequestURL() 获得 http://www.quanqiuyouhui.com/ds-api-test/authorization/test.do request.ge ...

  5. getContextPath、getServletPath、getRequestURI、getRealPath、getRequestURL、getPathInfo();的区别

    <% out.println("getContextPath: "+request.getContextPath()+"<br/>"); ou ...

  6. ${pageContext.request.contextPath}的解释以及和request.contextPath的区别

    JSP中究竟采用绝对路径还是采用相对路径随着所采用技术的越来越复杂,这个问题也变得越来越难以解决. 1)采用相对路径遇到的问题 l 相对路径固然比较灵活,但如果想复制页面内的代码却变得比较困难,因为不 ...

  7. Spring boot: Request method 'DELETE' not supported, Request method 'PUT' not supported, Request method 'POST' not supported

    GET,POST,PUT,DELETE, Spring都支持,不要怀疑Spring, 一定是前端发送的rest 请求和后端的响应不匹配, 查找原因以及解决办法, 很简单 用chrome打开F12控制台 ...

  8. AWS CloudFront CDN直接全站加速折腾记The request could not be satisfied. Bad request

    ERROR The request could not be satisfied. Bad request. Generated by cloudfront (CloudFront) Request ...

  9. request.getSession().setAttribute(&quot;&quot;,..)和request.setAttribute(&quot;&quot;,...)的差别

    request.getSession.setAttribute()是获得当前会话的session,然后再setAttribute到session里面去,有效范围是session而不是request. ...

随机推荐

  1. Hadoop-2.4.1学习之edits和fsimage查看器

    在hadoop中edits和fsimage是两个至关关键的文件.当中edits负责保存自最新检查点后命名空间的变化.起着日志的作用,而fsimage则保存了最新的检查点信息.这个两个文件里的内容使用普 ...

  2. 剑指offer 高速排序

    高速排序一般的写法.教科书上非常具体,这里介绍作者的写法. 程序例如以下: #include<iostream> #include<stack> using namespace ...

  3. ArcGIS鼠标滚轮方向之ArcMap篇

    ArcMap中地图缩放滚轮方向与我们常用的AutoCAD.在线地图等相反.ArcMap默认滚轮向上缩小,向下放大,曾经引起过多位用户的不满.好在ArcMap提供个性化设置. 打开ArcMap菜单栏-自 ...

  4. ubuntu12.04 lts 安装gcc 4.8

    gcc 4.8.1 是第一个完全支持C++11 的编译器,Windows上可以安装mingw版的,在sourceforge 上有下载,安装也比较方便.在Linux上安装的话需要首先安装一些依赖库.在U ...

  5. Docker镜像保存save、加载load

    (1)查看要要保存的镜像的ID [root@localhost docker]# docker images (2)保存镜像 [root@localhost docker]# docker save  ...

  6. markdown table语法

    普通的表格 | 一个普通标题 | 一个普通标题 | 一个普通标题 | | ------ | ------ | ------ | | 短文本 | 中等文本 | 稍微长一点的文本 | | 稍微长一点的文本 ...

  7. loadrunner -27778 https连接问题

    Error -27778: SSL protocol error when attempting to read with host "×××.*****"

  8. 如何删除Android studio中的注解代码

    http://blog.csdn.net/maimiho/article/details/52195081 先看下上面的文章.只是换下正则表达式即可 正则表达式:/\*[\s\S ]*

  9. 如何查看2to3.PY的帮助文档

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #如何查看2to3.PY的帮助文档 #http://tieba.baidu.com/p/3939904893 ...

  10. WinHttp编写HTTP服务器示例代码

    这是微软提供的示例程序,原文地址在此https://msdn.microsoft.com/en-us/library/windows/desktop/aa364640(v=vs.85).aspx HT ...