getContextPath、getServletPath、getRequestURI、getRealPath、getRequestURL、getPathInfo();的区别
<%
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();的区别的更多相关文章
- Servlet的getContextPath(), getServletPath(), getRequestURI(), getRealPath("/")
假定web application 名称为news,你在浏览器中输入请求路径: http://localhost:8080/news/main/list.jsp 则执行下面向行代码后打印出如下结果: ...
- request的getServletPath(),getContextPath(),getRequestURI(),getRealPath("/")区别
假定你的web application 名称为news,你在浏览器中输入请求路径: http://localhost:8080/news/main/list.jsp 则执行下面向行代码后打印出如下结果 ...
- getServletPath getRequestURI getRequestURL区别
getContextPath:/test //上下文,类似工程名 getServletPath:/test.jsp getRequestURI:/test/test.jsp ...
- getRequestURI()与getRequestURL()的区别
引于: http://hi.baidu.com/cloudxpc request.getRequestURI() 返回值类似:/xuejava/requestdemo.jsprequest.getRe ...
- (转)关于request.getServletPath(),request.getContextPath()的总结
文章完全转载自 : https://blog.csdn.net/qq_27770257/article/details/79438987 最近对于request中的几种“路径”有点混淆,查找网上资源都 ...
- servlet路径获取
本文章主要讨论以下几种request获取路径的方法: request.getServletPath() request.getPathInfo() request.getContextPath() r ...
- 二:Servlet
一:servlet开端 1.servlet是什么? a.就是一个java类 b.服务器端的小程序 c.处理用户请求 2.servlet的实现: a.实现Servlet接口 b.继承GenericSer ...
- 【Servlet】—在servlet中常混的请求路径
在页面请求,后台获取相关请求路径是,自己长搞混的几个路径,再次做次标记,不要每次使用想不起来是,都去写一个小的demo来测试. request.getContextPath(); request.ge ...
- 【转】request.getServletPath()和request.getPathInfo()用法
转自:https://my.oschina.net/sub/blog/182408 在 Web 中,我们通常需要获取 URL 相对于 Webapp 的路径,主要是下面的几个方法: request.ge ...
随机推荐
- Ubuntu14.04-OpenCV2和3共存相关设置
文章转自:http://blog.csdn.net/a356337092/article/details/73529635 安装依赖项: sudo apt-get install build-esse ...
- IdentityServer4入门二
在 IdentityServer4入门一 我们准备好了一个认证的服务端,这里做一个需要保护的API服务 首先,向解决方案新增一个项目.我们同样使用入门一的方式新增一个asp.net core Web程 ...
- [Java] JRE、JDK和JVM的区别
在Java语言的学习过程中,配置环境时首先会接触到JRE和JDK的概念,后面随着了解的深入,不可避免会学习到JVM. JRE,全称Java Runtime Environment,也被写成Java R ...
- vue中书写JSX一些坑-特殊属性名
举例说明, T1和T2引用Sub时, key2会出现在props以及data.attrs中, 而key则在data中 const Sub = ({data, props}) => { conso ...
- tcpdump抓包文件分段保存-指定时间或者指定大小
2018年09月06日 15:36:11 天已青色等烟雨来 阅读数:3628 版权声明:博客地址:blog.csdn.net/x356982611,未经允许不得转载,不得转载,不得转载 http ...
- SpringBoot RestTemplate接收文件,并将文件发送到另外一个程序进行存储
最近有个需求,接收用户上报的证书,并且保存起来,证书大小不到1M,但该证书的保存必须在另外一个程序进行,所以想到使用springboot接收上传文件后,再通过RestTemplate将文件发送给另外一 ...
- insmod mknod
insmod module 會在 /proc/devices/ 下產生 major number 及 device name ---------------------------- mknod 會使 ...
- mfc递归删除文件夹
BOOL myDeleteDirectory(CString directory_path) //删除一个文件夹下的所有内容 { BOOL ret=TRUE; CFileFind finder; CS ...
- thymeleaf中img标签图片src路径问题
转载自:解决java - Thymeleaf conditional img src 正确写法. <img class="layui-nav-img" th:src=&quo ...
- windows和Linux下定时启动或关闭服务
http://blog.csdn.net/clare504/article/details/17410643 1.Windows下的定时启动程序可以采用系统的计划和任务,定时启动服务可以在计划任务中添 ...