<%
out.println("getContextPath: "+request.getContextPath()+"<br/>");
out.println("getServletPath: "+request.getServletPath()+"<br/>");
out.println("getRealPath: "+request.getRealPath("/")+"<br/>");
out.println("getRequestURL: "+request.getRequestURL()+"<br/>");
out.println("getRequestURI: "+request.getRequestURI()+"<br/>");
  
%>

出来的输出效果为:

getContextPath: /ckswzl
getServletPath: /admin/login.jsp
getRealPath: D:\document\EclipseWorkSpace2\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\ckswzl\
getRequestURL: http://localhost:8080/ckswzl/admin/login.jsp
getRequestURI: /ckswzl/admin/login.jsp

getContextPath是返回的项目上下文的名字(其实也就是项目名);

getServletPath是返回的是项目名到当前jsp文件的路径(意思就是在这个项目首页到文件的路径)

getRequestURI是返回的是项目名到整个文件的请求路径

getRealPath是返回的文件所在的绝对路劲。相对于当前计算机的真实路径

getRequestURL是返回的整个URL的路径请求(意思就是返回的浏览器地址栏的整个地址)

request.getPathInfo();这个方法返回请求的实际URL相对于请求的serlvet的url的路径。

如果我们的 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"

getContextPath、getServletPath、getRequestURI、getRealPath、getRequestURL、getPathInfo();的区别的更多相关文章

  1. Servlet的getContextPath(), getServletPath(), getRequestURI(), getRealPath("/")

    假定web application 名称为news,你在浏览器中输入请求路径: http://localhost:8080/news/main/list.jsp 则执行下面向行代码后打印出如下结果: ...

  2. request的getServletPath(),getContextPath(),getRequestURI(),getRealPath("/")区别

    假定你的web application 名称为news,你在浏览器中输入请求路径: http://localhost:8080/news/main/list.jsp 则执行下面向行代码后打印出如下结果 ...

  3. getServletPath getRequestURI getRequestURL区别

    getContextPath:/test               //上下文,类似工程名 getServletPath:/test.jsp getRequestURI:/test/test.jsp ...

  4. getRequestURI()与getRequestURL()的区别

    引于: http://hi.baidu.com/cloudxpc request.getRequestURI() 返回值类似:/xuejava/requestdemo.jsprequest.getRe ...

  5. (转)关于request.getServletPath(),request.getContextPath()的总结

    文章完全转载自 : https://blog.csdn.net/qq_27770257/article/details/79438987 最近对于request中的几种“路径”有点混淆,查找网上资源都 ...

  6. servlet路径获取

    本文章主要讨论以下几种request获取路径的方法: request.getServletPath() request.getPathInfo() request.getContextPath() r ...

  7. 二:Servlet

    一:servlet开端 1.servlet是什么? a.就是一个java类 b.服务器端的小程序 c.处理用户请求 2.servlet的实现: a.实现Servlet接口 b.继承GenericSer ...

  8. 【Servlet】—在servlet中常混的请求路径

    在页面请求,后台获取相关请求路径是,自己长搞混的几个路径,再次做次标记,不要每次使用想不起来是,都去写一个小的demo来测试. request.getContextPath(); request.ge ...

  9. 【转】request.getServletPath()和request.getPathInfo()用法

    转自:https://my.oschina.net/sub/blog/182408 在 Web 中,我们通常需要获取 URL 相对于 Webapp 的路径,主要是下面的几个方法: request.ge ...

随机推荐

  1. AGC009C Division into Two

    题意 有\(n\)个严格升序的数,请你分成两个集合\(A\)和\(B\),其中一个集合任意两数之差不小于\(x\),另一集合任意两数之差不小于\(y\). 问方案数,集合可以为空. $n \le 10 ...

  2. easyui的combobox模糊搜索

    <tr> <th>测试名称:</th> <td> <select data-options="" class="ea ...

  3. elasticsearch shield在java中的应用

    官方文档:https://www.elastic.co/guide/en/shield/current/_using_elasticsearch_java_clients_with_shield.ht ...

  4. 异步机制 - APC

    APC : An asynchronous procedure call,异步过程调用,是微软提供的一种在线程上下文中执行代码的机制.当向一个线程插入一个USER APC时,如果线程进入alertab ...

  5. fiddler 基本知识(一)

    工作原理: fiddler,原理是在本机开启了一个http代理服务器,默认监听127.0.0.1:8888. 打开fiddler之后,会帮我们设置ie代理,虽然只设置了ie,但整个计算机都通过整个代理 ...

  6. OpenResty之ngx.ssl

    翻译自: ngx.ssl - Lua API for controlling NGINX downstream SSL handshakes 1. 概要 # 注意:如果你使用的是 OpenResty ...

  7. 分布式系统的应用程序性能监视工具,专为微服务、云本机架构和基于容器(Docker、K8s、Mesos)架构而设计。 SkyWalking

    Apache SkyWalking™ | SkyWalking Teamhttp://skywalking.apache.org/zh/ Application performance monitor ...

  8. 全国数据json

    { "provinces": { "province": [ { "ssqid": "110000", "ss ...

  9. 阶段5 3.微服务项目【学成在线】_day02 CMS前端开发_09-webpack研究-webpack介绍

    使用vue.js开发大型应用需要使用webpack打包工具,本节研究webpack的使用方法. 1.3.1 webpack介绍 Webpack 是一个前端资源的打包工具,它可以将js.image.cs ...

  10. 关于对VGA、DVI、HDMI的区别

    VGA接口: DVI接口: HDMI接口 可以这么理解: 1. VGA传输普通视频信号,DVI传输高清视频信号,HDMI传输高清视频信号并支持音频传输.2. HDMI的三种接口只有大小区别,功能没有任 ...