request 路径随笔
1. 路劲可分为 绝对路径 和 相对路径
2. 绝对路径 (开头带"/")
前端: http://localhost:8080/myWebApp/user/login.jsp
/myWebApp/user/login.jsp
后端: /user/login.jsp
这里可以看出一个区别, 其中"/"这个斜杠在前后端有着不同的意义:
前端--> (表示) 服务器的根路径(例如:http://localhost:8080/)
后端-->(表示) 应用的根路径 (例如: http://localhost:8080/yourWebAppName/)
3. 相对路径 (开头不带"/")
举个例子, 假如当前的路径是 http://localhost:8080/myWebApp/user/login.jsp
那么这时候访问 “main.jsp”页面,即访问的是 http://localhost:8080/myWebApp/user/main.jsp
也就是说,使用相对路径,那么访问的是 当前页面路径 所属 目录 下的文件路径。
这个特性无论是在前端 、 后端 都是一样的。
在java中,无论是JSP或者Servlet , 都可以通过request这个对象获得requestURL( ) , 该方法返回当前所访问的页面的绝对路径的一个StringBuilder。
应用服务器正是通过该路径来得到用户想要访问的页面路径。
而一般使用forward时,就是通过修改该路径(无论当前指定的是绝对路径或者相对路径),来请求新的路径。
Base path :scheme+serverName+serverport+requestContext): http://192.168.10.64:8080 //应用路径
req.reqeustURL(): http://192.168.10.64:8080/testPath/test.do //请求路径
req.requestURI(): /testPath/test.do //请求路径(相对服务器根目录部分)
req.getSession.getServletContext().getRealPath("")F:\tomcat\apache-tomcat-7.0.47\webapps\testPath
//根目录的真实路径
req.getSession().getServletContext().getResource("/") : jndi:/localhost/testPath/index.jsp //这里必须要‘/'开头
req.getServletPath(): /test.do //servlet的映射路径
req.getSession().getServletContext().getContextPath() : /testPath //应用上下文路径(标准的)
req.getContextPath(): //请求request 所指向的应用上下文路径 一般为应用路径,即/AppName (如果场景是把整个应用服务器当成一个应用,所以应用上下文为"/testPath")
testPath App
/testPath
req.getRealPath("file.upload") :
F:\tomcat\apache-tomcat-7.0.47\webapps\testPath\file.upload
req.getSession().getServletContext().getResource("/") :
jndi:/localhost/testPath/index.jsp
req.getSession.getServletContext().getRealPath("") :
F:\tomcat\apache-tomcat-7.0.47\webapps\testPath
req.getSession().getServletContext().getContextPath() :
/testPath
req.getRequestURL() :
http://192.168.10.64:8080/testPath/test.do
req.getRequestURI() :
/testPath/test.do
req.getAuthType() :
null
req.getMethod() : :
GET
req.getQueryString() :
null
req.getContentType() :
null
req.getContextPath() :
/testPath
req.getContentLength() :
-1
req.getLocale() :
zh_CN
req.getLocalAddr() :
192.168.10.64
req.getLocalName() :
c-PC
req.getLocalPort() :
8080
req.getRemoteAddr() :
192.168.10.64
req.getRemoteHost() :
192.168.10.64
req.getRemotePort() :
61783
req.getRemoteUser() :
null
req.getScheme() :
http
req.getServerName() :
192.168.10.64
req.getServerPort() :
8080
req.getServletPath() :
/test.do
/testPath
req.getScheme()+"://"+req.getServerName()+":"+req.getServerPort()+path+"/" :
http://192.168.10.64:8080/testPath/ ROOT
req.getContextPath() :
""
req.getRealPath("file.upload") :
F:\tomcat\apache-tomcat-7.0.47\webapps\ROOT\file.upload
req.getSession().getServletContext().getResource("/") :
jndi:/localhost/index.jsp
req.getSession.getServletContext().getRealPath("") :
F:\tomcat\apache-tomcat-7.0.47\webapps\ROOT
req.getSession().getServletContext().getContextPath() :
req.getRequestURL() :
http://192.168.10.64:8080/test.do
req.getRequestURI() :
/test.do
req.getAuthType() :
null
req.getMethod() : :
GET
req.getQueryString() :
null
req.getContentType() :
null
req.getContextPath() :
req.getContentLength() :
-1
req.getLocale() :
zh_CN
req.getLocalAddr() :
192.168.10.64
req.getLocalName() :
c-PC
req.getLocalPort() :
8080
req.getRemoteAddr() :
192.168.10.64
req.getRemoteHost() :
192.168.10.64
req.getRemotePort() :
61836
req.getRemoteUser() :
null
req.getScheme() :
http
req.getServerName() :
192.168.10.64
req.getServerPort() :
8080
req.getServletPath() :
/test.do
req.getScheme()+"://"+req.getServerName()+":"+req.getServerPort()+path+"/" :
http://192.168.10.64:8080/
request 路径随笔的更多相关文章
- 超全面的JavaWeb笔记day10<Response&Request&路径&编码>
1.Response 2.Request 3.路径 4.编码 请求响应流程图 response 1.response概述 response是Servlet.service方法的一个参数,类型为java ...
- 项目vue2.0仿外卖APP(二)
vue-cli开启vue.js项目 github地址:https://github.com/vuejs/vue-cli Vue.js开发利器vue-cli,是vue的脚手架工具. 在工地上,脚手架是工 ...
- Python之Web框架Django
Python之Web框架: Django 一. Django Django是一个卓越的新一代Web框架 Django的处理流程 1. 下载地址 Python 下载地址:https://www.pyt ...
- OWIN的理解和实践(三) –Middleware开发入门
上篇我们谈了Host和Server的建立,但Host和Server无法产出任何有实际意义的内容,真正的内容来自于加载于Server的Middleware,本篇我们就着重介绍下Middleware的开发 ...
- 【jmeter】WebSerivice测试
WebSerivice测试计划的取样器有两种方式:HTTP请求.SOAP/XML-RPC Request. 1. 测试计划 启动JMeter,点击测试计划节点上,重命名测试计划:WebserviceT ...
- Day17 表单验证、滚动菜单、WEB框架
一.表单验证的两种实现方式 1.DOM绑定 <!DOCTYPE html> <html lang="en"> <head> <meta c ...
- Python 一路走来 Django
Web 框架 (本质:socket) Python web框架 自己实现socket - Tornado 基于wsgi ...
- Middleware开发入门
Middleware开发入门 上篇我们谈了Host和Server的建立,但Host和Server无法产出任何有实际意义的内容,真正的内容来自于加载于Server的Middleware,本篇我们就着重介 ...
- Spring @Pathvariable
先记录下@PathVariable的用法吧: @RequestMapping("/demo/{id}") @ResponseBody public User getUser(@Pa ...
随机推荐
- CSS之隐藏元素
1.opacity=0,该元素隐藏起来了,但不会改变页面布局,并且,如果该元素已经绑定一些事件,如click事件,那么点击该区域,也能触发点击事件的2.visibility=hidden,该元素隐藏起 ...
- SQLServer触发器的使用
创建: create trigger trigger_name on {table_name view_name} {for After Instead of } [ insert, update,d ...
- python:笔记for循环中的else
我们常常会在for循环遍历一个序列或者字典后,接着语句else,很多新手会误以为是判断执行else后面的 代码,其实不然,for循环里面也不存在判断,而已执行完遍历的对象后,再执行else后面的代码. ...
- 关联表映射 Association Table Mapping
把关联保存为一个表,存储关联表的外键 在对象中,使用集合作为域值,来处理多值域. 而在DB中,只能有单值域. 外键映射的核心,是在关联关系的单值端使用外键来维持联系. 而在多对多的关联关系中,已经不存 ...
- CSS制作彩虹效果
今天看到一篇文章,说到margin的塌陷的问题,并提供了好几个例子. 自己之前还没怎么遇到过这个问题,正好来研究一下. <div class="box1"></d ...
- Codevs 1205 单词翻转
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 青铜 Bronze 题解 题目描述 Description 给出一个英语句子,希望你把句子里的单词顺序都翻转过来 输入 ...
- ubuntu 常用参数设置
在Linux下,对于参数的设置,一般来说,都遵循这个规律.每一个功能程序,一定对于一个对于名字的配置文件. 涉及到多用户的功能配置,一定有一个全局的配置文件,对所有用户都生效,而每个用 ...
- Ubuntu14.04 安装 PHP cURL
今天遇到 Fatal error: Call to undefined function curl_init() in /xxx/xxxx/www/application/library/Ku/Htt ...
- Spring MVC与easyui国际化
1.建立资源文件 在webapp下建立文件夹language,在其中再添加file,命名分别为language.properties,language_en.properties,language_z ...
- ExtJS实战 01——HelloWorld
前言 Extjs5的发布已经有些日子了,目前的最新稳定版本是Extjs5.1.0,我们可以在官方网站进行下载.不过笔者今天访问得到的是502Bad Gateway,原因可能是sencha的nigix没 ...