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 ...
随机推荐
- Js 之获取对象key值
var date = Object.keys(data); Object.keys( ) 会返回一个数组,数组中是这个对象的key值列表 所以只要Object.keys(a)[0], 就可以得只包含一 ...
- instr动态模糊查询
String sqlSearchtext = ""; if(!"".equals(model.getXzqhdm())&&model.getXz ...
- elasticsearch shield(5.0以下版本 权限认证)
elasticsearch 5.0以下的版本要用到权限控制的话需要使用shield.下载地址: https://www.elastic.co/downloads/shield5.0以上的版本则可以使用 ...
- docker 部署 .net core
1.centos安装好sdk2.1,安装好docker,这些基本的操作就不赘述. 2.准备好core项目,版本2.1 3.新建dockerfile文件放到项目发布文件夹里,里面内容如下: FROM m ...
- csp-s模拟106
这场其实心态十分爆炸,首先一下午改上次破T3卡常一下午没过,心情十分暴躁.上来开题不顺利,T1想了一个小时没动.于是跳到T2,看T2的80pts貌似可拿就先打了.T3只会判10分,又想打个$2^{2N ...
- 重读APUE(7)-link/unlink与mkdir/rmdir
link–用于创建一个现有文件的链接:实际上是新建一个目录项,指向当前文件的i节点: unlink–用于删除一个现有文件的连接:实际上是对引用i节点的目录项进行删除,并且对链接计数-1:系统会检查文件 ...
- ArcGIS超级工具SPTOOLS-拓扑错误处理
1.1 删除线面直线上的点 操作视频: https://weibo.com/tv/v/Hxjgmuv6F?fid=1034:4379388532225679 删除面要素.线要素一条边直线上的点. 1 ...
- 安装mysql后必须要做的一件事
Step 1. 检查默认账户和密码 $cat /etc/mysql/debian.cnf # 在ubuntu下查看默认账户名和密码 会看到 [client] host = localhost user ...
- [Java复习] Spring Boot
什么是Spring Boot? 传统SSH/SSM框架配置繁琐,有很多重复的模板配置,效率不高. Spring Boot快速创建可独立运行,生产级别的Spring应用程序. 主要是基于Spring家族 ...
- java网络通信:异步非阻塞I/O (NIO)
转: java网络通信:异步非阻塞I/O (NIO) 首先是channel,是一个双向的全双工的通道,可同时读写,而输入输出流都是单工的,要么读要么写.Channel分为两大类,分别是用于网络数据的S ...