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 ...
随机推荐
- redhat7.4安装git(按照官网从源码安装)
按照官方文档建议使用源码安装 1.为什么不用yum安装 yum安装确实简单,只用一行命令就可以了,但是yum安装的版本太低. //安装前使用info查看git版本信息等 yum info git yu ...
- Resend a Request by fiddler
Resend a Request You can resend a request directly from the Sessions List, or save requests to resen ...
- Python 学习 —— 进阶篇(装饰器、类的特殊方法)
Python基础部分学完之后,在进入其OOP部分前,先理解一下其装饰器这种结构,其功能可类比于Java中的面向切面编程,下面参见具体实例: def log(f): def fn(x): print ' ...
- Flex 弹性盒子布局使用教程
本文转载于<https://blog.csdn.net/lyznice/article/details/53981062>
- 阶段5 3.微服务项目【学成在线】_day02 CMS前端开发_09-webpack研究-webpack介绍
使用vue.js开发大型应用需要使用webpack打包工具,本节研究webpack的使用方法. 1.3.1 webpack介绍 Webpack 是一个前端资源的打包工具,它可以将js.image.cs ...
- Qt编写自定义控件23-广告轮播控件
一.前言 广告轮播这个控件做的比较早,是很早以前定制一个电信客户端时候用到的,该客户端需要在首页展示轮播预先设定好的图片,图片的路径可以自由设定,然后轮播的间隔速度可以自由控制,同时该控件还需要提供两 ...
- Java NIO 学习笔记 读写结合补充
小练习:nio读写文件,将fileread中的内容读取到filewrite中 try { //创建输入通道 FileInputStream fis = new FileInputStream(&quo ...
- Cloudera Manager 概念
cloudera公司发布的CDH集群,使用Cloudera Manager来管理整个集群,使用过程中主要涉及到几个关键概念:cluster.service.role.host.直接上图,直观理解几个概 ...
- nginx反向代理本地 单台wed -使用ip+端口代理
环境: 本地外网ip:123.58.251.166 .配置index.html网页 [root@host---- conf.d]# cat /web/sing/index.html <h1> ...
- Example config file /etc/vsftpd.conf
# Example config file /etc/vsftpd.conf # # The default compiled in settings are fairly paranoid. Thi ...