request.getContextPath()使用
来源:互联网 发布:广电总局封网络电视 编辑:程序博客网 时间:2024/06/16 17:34
看到很多人都喜欢用<%=request.getContextPath()%>
那我也使用一下
<%=request.getContextPath()%>是解决相对路径的问题,可返回站点的根路径。
<a href="<%=request.getContextPath()%>/XXX.jsp"> //这样获得的是绝对路径
<a href="XXX.jsp"> //这样获得的是相对路径
<a href="<%=request.getContextPath()%>/XXXX.jsp"> 能够更有效的防治连接的失效。
request.getContextPath()得到的是项目的名字,如果项目为根目录,则得到一个"",即空的字条串,
如果项目为dzjc, <%=request.getContextPath()% >/ 将得到dzjc/,服务器端的路径则会自动加上,
<a href="XXX.jsp"> 应该就是指当前路径下的这个xxx.jsp页面,有时候也可以在head里设置html:base
来解决路径的问题,不过用的最多的还是request.getContextPath。
用EL来表示相同功能的EL为:${pageContext.request.getContextPath()}
request.getScheme();
返回的协议名称,默认是http
request.getServerName()
返回的是你浏览器中显示的主机名
getServerPort()
获取服务器端口号
如果想得到工程文件的实际物理路径,可通过:<%=request.getRealPath("/")%>,这样页面就会输出:d:/web
现在request.getRealPath("") 这个方法已经不推荐使用了
可以使用
ServletContext.getRealPath(java.lang.String) instead. request.getSession().getServletContext().getRealPath() 得到工程文件的实际物理路径,也就是绝对地址
- 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()的含义及使用
- 明天我就要回家,一首老歌送给大家
- iOS项目笔记-sqlite数据库操作
- 初识安卓小程序(Android电话拨号器)
- <!-- <s:action name="navAllFront" namespace="/nav" executeResult="true" flush="false"></s:action>
- 抛出 异常 You have an error in your SQL syntax...
- request.getContextPath()使用
- CSDN上第一次写文章,胡说八道
- UML学习——组件,衍型、子系统、类
- SRS产品对比
- 九度 1127
- DataGrid_ItemCommand() 的成功执行
- Poj 2488 A Knight's Journey
- 类图和对象图
- document.write();