转自:http://blog.sina.com.cn/s/blog_6cbe0cff0101j6jl.html

request.getContextPath()是在开发Web项目时,经常用到的方法,其作用是获取当前的系统路径。

当使用Tomcat作为Web服务器,项目一般部署在Tomcat下的webapps的目录下。具体来说主要用两种部署的路径:

一是将web项目中的webRoot下的文件直接拷贝到webapps/ROOT下(删除ROOT下的原有文件);

另一中方法在Tomcat下的webapps中创建以项目名称命名(当然也可以用其他的名称)的文件夹,并将webRoot下的文件直接拷贝到该文件夹下。

对于第一部署方法,request.getContextPath()的返回值为空(即:"",中间无空格,注意区分null)。

对于第二部署方法,其返回值为:/创建的文件夹的名称。

另外,对于SmartUpload.downloadfile()方法,其文件名参数中的路径部分是一个相对路径,并不包含由request.getContextPath()函数读取的部分,而仅仅包含该路径下的路径。

getContextPath效果

2007年07月13日 星期五 下午 01:11

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

path IS: /jspSmartUpLoad

basePath IS: http://yangm1203.oicp.net:8080/jspSmartUpLoad/

request.getScheme() IS: http

request.getServerName() IS: yangm1203.oicp.net

request.getServerPort() IS: 8080

idea中设置当前项目的目录:

现在设置的是test,相当于把项目部署到了webapps下的test目录下,如果不设置,默认是/,就是ROOT目录下

现在访问的路径就应该是:losthost:8080/test/xxxxx

request.getContextPath()返回值问题的更多相关文章

  1. Spring-boot 配置Aop获取controller里的request中的参数以及其返回值

    首先在你的Maven的pom文件里加入aop的依赖: <dependency> <groupId>org.springframework.boot</groupId> ...

  2. request.getcontextPath() 详解

    request.getcontextPath() 详解 文章分类:Java编程 <%=request.getContextPath()%>是为了解决相对路径的问题,可返回站点的根路径. 但 ...

  3. request.getcontextPath() 详解(转)

    本文转自:http://blog.csdn.net/pengxuan/article/details/6604578 <%=request.getContextPath()%>是为了解决相 ...

  4. request.getcontextPath() 详解 和 <link标签>

    classpath:只会到你的class路径中查找找文件; classpath*:不仅包含class路径,还包括jar文件中(class路径)进行查找. 绝对路径: D:\磊弟资料\最代码\智父子考试 ...

  5. JSP之项目路径问题(${pageContext.request.contextPath},<%=request.getContextPath()%>以及绝对路径获取)

    本随笔这是作为一个记录使用,以备后查.项目完成之后本地部署OK,本地Linux部署OK,都可以正常的访问,可是当我把它部署到服务器上面的时候,首页可以正常访问,可是当发出请求的时候却报错误了,说找不到 ...

  6. request.getContextPath()

    今天终于明白了jsp中的request.getContextPath()是怎么回事了. request.getContextPath()  返回站点的根目录 request.getRealpath(& ...

  7. jsp中【<%=request.getContextPath()%>】项目路径

    1 2 "request.getContextPath()的值是        "<%=request.getContextPath()%><br/> &q ...

  8. <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>

    <%String path = request.getContextPath();String basePath = request.getScheme()+"://"+re ...

  9. 关于String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

    关于 String path = request.getContextPath(); String basePath = request.getScheme()+"://"+req ...

随机推荐

  1. linux查看内存及磁盘使用情况

    1.查看当前目录 命令:   df -h       (统一每个目录下磁盘的整体情况) 2.查看指定目录 在命令后直接放目录名,比如查看"usr"目录使用情况: 命令:   df ...

  2. 【刷题笔记】DP优化-状压

    因为篇幅太长翻着麻烦,计划把DP拆成几个小专题,这里原文只留下状压,其他请至后续博文. 状态压缩优化 所谓状态压缩,就是将原本需要很多很多维来描述,甚至暴力根本描述不清的状态压缩成一维来描述. 时间复 ...

  3. 第一次UML编程作业

    博客班级 https://edu.cnblogs.com/campus/fzzcxy/2018SE2/ 作业要求 https://edu.cnblogs.com/campus/fzzcxy/2018S ...

  4. fist-第一天随笔

    这个作业属于哪个课程 https://edu.cnblogs.com/campus/fzzcxy/2018SE1 这个作业要求在哪里 https://edu.cnblogs.com/campus/fz ...

  5. Elasticsearch基本CURD操作语法讲解

    当我们的ES集群搭建完成以后,我怎么能看到集群中各个节点状态以及主节点和健康情况呢,如下讲解使用curl命令来与ES集群进行交互.分别有查询主节点情况.集群状态.以及创建索引查看索引.查看分片以及对E ...

  6. Spring Boot + Elasticsearch 使用示例

    本文分别使用 Elasticsearch Repository 和 ElasticsearchTemplate 实现 Elasticsearch 的简单的增删改查 一.Elastic Stack El ...

  7. 20200116_centos7.2 下 mysql_5.7修改root密码

    1. 需改my.cnf文件 [root@rakinda-iot-platform ~]# vim /etc/my.cnf 2. 新增一行, 登录时跳过密码, 保存后退出, 重启mysql system ...

  8. Mybatis学习-配置、作用域和生命周期

    核心配置文件:Mybatis-config.xml Mybatis的配置文件包含了会深深影响Mybatis行为的设置和属性信息 配置(configuration) 在mybatis-config.xm ...

  9. Jmeter录制脚本-BadBoy

    录制脚本方式: 1)Badboy录制Jmter脚本 2)Jmter代理服务录制脚本 方式一:Badboy录制脚本 安装Badboy 录制脚本 1.双击Badboy 2.输入URL 3.点击" ...

  10. windows 10 扩大C盘空间

    DiskGenius工具去对windows 10空间进行扩容 1.DiskGenius,可以通过官网进行下载:http://www.diskgenius.cn/download.php 2.DiskG ...