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. 如何通过 iframe 共享 jQuery $.data?

    index.html <div id="div1"> </div> <iframe src="ajax2.html" name=& ...

  2. iOS中文API之UITouch详解

    UITouch 对象用于位置. 大小. 运动和一根手指在屏幕上为某一特定事件的力度.触摸的力度是从开始在 iOS 9 支持 3D 的触摸的设备上可用.你可以通过UIEvent对象传递给响应者对象访问. ...

  3. 【Nodejs】使用request批量下载MP3,文件数量内容都没问题

    看来request远强于http.request是毋庸置疑的了. 代码如下: //====================================================== // 喜 ...

  4. Spring Integration概述

    1.   Spring Integration概述 1.1     背景 Spring框架的一个重要主题是控制反转.从广义上来说,Spring处理其上下文中管理的组件的职责.只要组件减轻了职责,它们同 ...

  5. php学习实例3

    新闻发布管理系统 路由器action.php <!DOCTYPE html> <html> <head> <title> </title> ...

  6. 再玩 DevStack(Mitaka版)- 基于 trystack.cn 源

    曾经就写过一篇关于DevStack安装OpenStack的文章< 使用 DevStack 高速部署 OpenStack 开发环境 >,时过境迁,如今有更好的方式来实现.想到曾经的复杂性,认 ...

  7. CyclicBarrier的用法

    CyclicBarrier是一个同步辅助类,它允许一组线程互相等待,直到到达某个公共屏障点 (common barrier point).在涉及一组固定大小的线程的程序中,这些线程必须不时地互相等待, ...

  8. ajax请求,返回值为304 Not Modified 错误原因与解决办法

    先说原因吧,这是因为http请求的缓存问题引起的 前后调用了两个相同的请求,服务器懒得给你重新发一个请求,所以就304咯 那怎么办呢? 解决方法也很简单,加一个时间戳就行了 比如: 原请求为: $.g ...

  9. JSP九大内置对象辨析

    转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6043096.html JSP中一共预先定义了9个这样的对象,分别为:request.response.sess ...

  10. Oracle---->Join

    最近使用ODI,其中有一个JOIN组件涉及到常见的几种JOIN类型,因此整理了下交叉连接和自然连接的区别. 一.概述 两个表的连接,是通过将一个表中的一列或者多列同另一个表中的列链接而建立起来的.用来 ...