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 路径随笔的更多相关文章

  1. 超全面的JavaWeb笔记day10<Response&Request&路径&编码>

    1.Response 2.Request 3.路径 4.编码 请求响应流程图 response 1.response概述 response是Servlet.service方法的一个参数,类型为java ...

  2. 项目vue2.0仿外卖APP(二)

    vue-cli开启vue.js项目 github地址:https://github.com/vuejs/vue-cli Vue.js开发利器vue-cli,是vue的脚手架工具. 在工地上,脚手架是工 ...

  3. Python之Web框架Django

    Python之Web框架: Django 一. Django Django是一个卓越的新一代Web框架 Django的处理流程 1. 下载地址  Python 下载地址:https://www.pyt ...

  4. OWIN的理解和实践(三) –Middleware开发入门

    上篇我们谈了Host和Server的建立,但Host和Server无法产出任何有实际意义的内容,真正的内容来自于加载于Server的Middleware,本篇我们就着重介绍下Middleware的开发 ...

  5. 【jmeter】WebSerivice测试

    WebSerivice测试计划的取样器有两种方式:HTTP请求.SOAP/XML-RPC Request. 1. 测试计划 启动JMeter,点击测试计划节点上,重命名测试计划:WebserviceT ...

  6. Day17 表单验证、滚动菜单、WEB框架

    一.表单验证的两种实现方式 1.DOM绑定 <!DOCTYPE html> <html lang="en"> <head> <meta c ...

  7. Python 一路走来 Django

    Web 框架 (本质:socket) Python web框架           自己实现socket                - Tornado           基于wsgi       ...

  8. Middleware开发入门

    Middleware开发入门 上篇我们谈了Host和Server的建立,但Host和Server无法产出任何有实际意义的内容,真正的内容来自于加载于Server的Middleware,本篇我们就着重介 ...

  9. Spring @Pathvariable

    先记录下@PathVariable的用法吧: @RequestMapping("/demo/{id}") @ResponseBody public User getUser(@Pa ...

随机推荐

  1. 读书笔记-常用设计模式之MVC

    1.MVC(Model-View-Controller,模型-视图-控制器)模式是相当古老的设计模式之一,它最早出现在SmallTalk语言中.MVC模式是一种复合设计模式,由“观察者”(Observ ...

  2. UI4_UITableViewSectionIndex

    // AppDelegate.m // UI4_UITableViewSectionIndex // // Created by zhangxueming on 15/7/14. // Copyrig ...

  3. c++学习——类成员的访问权限

    成员的访问权限 Public: 任何人,尤其是那些要使用这个类库的客户程序员,都能访问那个紧跟在public 后面声明的成员. 默认的package: 在同一个目录里面的文件,并且都没有明确指明它是属 ...

  4. 洛谷 P3374 【模板】树状数组 1

    题目描述 如题,已知一个数列,你需要进行下面两种操作: 1.将某一个数加上x 2.求出某区间每一个数的和 输入输出格式 输入格式: 第一行包含两个整数N.M,分别表示该数列数字的个数和操作的总个数. ...

  5. 《RHEL6硬盘的分区和swap分区管理》——硬盘分区的大总结

    首先介绍下几个简单的命令: free查看当前系统内存的使用情况 查看分区的使用情况:T类型.H显示大小以G,M 查看系统所有硬盘的分区信息:分区的没分区的都显示出来了 开始分区:为什么要加cu  不加 ...

  6. <a href="onclick="javascript:goSearch(this)" class="click" name="Java">Java</a>为什么a标签的父节点获取不到

    <script> function goSearch(event) { //var select = $('#keyInput').val($(event).attr("name ...

  7. APUE习题8.7

    看书的时候发现这个习题没有答案,于是就想把自己做的结果贴上来,和大家分享分享! 首先把题目贴上来吧: /*********** 8.10节中提及POSIX.1要求在调用exec时关闭打开的目录流.按下 ...

  8. Amazon Kinesis Producer Library 使用记录

    Amazon Kinesis 是一种托管的服务,用于有弹性与扩展性的实时处理大规模的流数据.该服务收集大数据记录流,多个可在 Amazon EC2 实例上运行的数据处理应用程序随后可实时使用此流. 在 ...

  9. FastDFS4 + Ubuntu12安装及部署

    1. 安装libevent 如果需要使用http进行下载,需要安装这个组件. 2. 安装fastdfs 3. 配置fastdfs 4. 安装nginx 问题4.1:安装nginx启动后访问原先资源UR ...

  10. 封装cookie

    function cookie(name,value,expires){ switch(typeof value){ case 'string': //设置 var exp=''; if(expire ...