request.getContextPath()使用
来源:互联网 发布:centos 解压缩 编辑:程序博客网 时间:2024/06/05 04:42
request.getcontextPath() 详解
<%=request.getContextPath()%>是为了解决相对路径的问题,可返回站点的根路径。
但不用也可以,比如<a href="<%=request.getContextPath()%>/catalog.jsp">直接用<a href="catalog.jsp">也行,这两个文件是在同一个目录下的。比如你要生成一个文件放在服务器上得一个目录下,你可以使用request.getContextPath()+/dir,组成一个完整得目录结构!
但在jsp文件里,通过request.getContextPath()得到的路径却为空,为什么?
你在context中没有配置path属性,所以你的工程文件就是在根目录下,相当于path="";即是你直接在浏览器中输入你的服务器ip就会到你的jsp页面,而不是tomcat的默认页面;所以你通过request.getContextPath()得到的字符串是为空的;它是获得虚目录的;
如果你想得到工程文件的实际物理路径,可通过:<%=request.getRealPath("/")%>,这样页面就会输出:d:/web
request.getScheme();
返回的协议名称,默认是http
request.getServerName()
返回的是你浏览器中显示的主机名,你自己试一下就知道了
getServerPort()
获取服务器端口号
request.getContextPath()应该是得到项目的名字,如果项目为根目录,则得到一个"",即空的字条串,如果项目为abc, <%=request.getContextPath()% >/ 将得到abc/,服务器端的路径则会自动加上,<a href="xxx.jsp"> 应该就是指当前路径下的这个xxx.jsp页面,有时候也可以在head里设置html:base来解决路径的问题,不过用的最多的还是request.getContextPath。
- request.getContextPath()使用
- request.getContextPath()使用
- 无法使用request.getContextPath()解决办法
- request.getContextPath();
- request.getContextPath()
- request.getContextPath()
- request.getcontextPath()
- request.getContextPath()
- request.getContextPath()
- request.getContextPath()
- request.getContextPath()
- request.getContextPath()
- request.getContextPath()
- request.getContextPath
- request.getContextPath()
- request.getContextPath()
- pagecontext.request.getcontextpath和request.getContextPath()
- request.getSchema(),request.getServerName(),request.getServerPort(),request.getContextPath()的含义及使用
- Codeforces Round #230 (Div. 2)B. Three matrices
- zigbee学习笔记--电源管理OSAL机制的ZigBee低功耗管理(CC2530)
- 一点小感触
- Android基础学习篇之一:Intent初步
- 读书笔记
- request.getContextPath()使用
- zju3261 Connections in Galaxy War
- thinkphp学习--入口文件--1
- MFileServer管理员用户名密码配置
- 【已禁用】WeixinJSBridge:微信浏览器内置JavaScript 对象
- 如何调用cocostudio创建场景中的按钮控件
- 二、Windows下制作Clover引导的Mavericks系统安装U盘
- Linux 进程的内存管理
- datagridview绑定数据之后如何增加行