${pageContext.request.contextPath} :JSP取得绝对路径方法
来源:互联网 发布:oecd怎么下载数据啊 编辑:程序博客网 时间:2024/06/04 01:02
1)采用绝对路径,但为了解决不同部署方式的差别,在所有非struts标签的路径前加${pageContext.request.contextPath},如原路径为:
”/images/title.gif”,改为
“${pageContext.request.contextPath}/images/title.gif”。
代码” ${pageContext.request.contextPath}”的作用是取出部署的应用程序名,这样不管如何部署,所用路径都是正确的。
缺点:
操作不便,其他工具无法正确解释${pageContext.request.contextPath}
2) 采用相对路径,在每个JSP文件中加入base标签,如:
<base href="http://${header['host']}${pageContext.request.contextPath}/pages/cust/relation.jsp" />
这样所有的路径都可以使用相对路径。
缺点:
对于被包含的文件依然无效。
真正使用时需要灵活应用1)和2),写出更加健壮的代码。
在使用的时候可以使用${pageContext.request.contextPath},也同时可以使用<%=request.getContextPath()%>达到同样的效果,同时,也可以将${pageContext.request.contextPath},放入一个JSP文件中,将用C:set放入一个变量中,然后在用的时候用EL表达式取出来。
如:
”/images/title.gif”,改为
“${pageContext.request.contextPath}/images/title.gif”。
代码” ${pageContext.request.contextPath}”的作用是取出部署的应用程序名,这样不管如何部署,所用路径都是正确的。
缺点:
操作不便,其他工具无法正确解释${pageContext.request.contextPath}
2) 采用相对路径,在每个JSP文件中加入base标签,如:
<base href="http://${header['host']}${pageContext.request.contextPath}/pages/cust/relation.jsp" />
这样所有的路径都可以使用相对路径。
缺点:
对于被包含的文件依然无效。
真正使用时需要灵活应用1)和2),写出更加健壮的代码。
在使用的时候可以使用${pageContext.request.contextPath},也同时可以使用<%=request.getContextPath()%>达到同样的效果,同时,也可以将${pageContext.request.contextPath},放入一个JSP文件中,将用C:set放入一个变量中,然后在用的时候用EL表达式取出来。
如:
<c:set var="ctx" value="${pageContext.request.contextPath}" />
阅读全文
0 0
- ${pageContext.request.contextPath} :JSP取得绝对路径方法
- ${pageContext.request.contextPath} :JSP取得绝对路径方法
- ${pageContext.request.contextPath} :JSP取得绝对路径方法
- ${pageContext.request.contextPath} :JSP取得绝对路径方法
- ${pageContext.request.contextPath} :JSP取得绝对路径方法
- ${pageContext.request.contextPath} :JSP取得绝对路径方法
- ${pageContext.request.contextPath} :JSP取得绝对路径方法
- ${pageContext.request.contextPath} :JSP取得绝对路径方法
- ${pageContext.request.contextPath} JSP取得绝对路径
- ${pageContext.request.contextPath} JSP取得绝对路径
- ${pageContext.request.contextPath} JSP取得绝对路径
- ${pageContext.request.contextPath} JSP取得绝对路径
- ${pageContext.request.contextPath} JSP取得绝对路径
- ${pageContext.request.contextPath} JSP取得绝对路径
- ${pageContext.request.contextPath} JSP取得绝对路径
- ${pageContext.request.contextPath} JSP取得绝对路径
- ${pageContext.request.contextPath} JSP取得绝对路径
- ${pageContext.request.contextPath} JSP取得绝对路径
- ios学习之基于 OpenCV的人脸识别
- caffe MNIST手写数字识别例程
- 51Nod 1073 约瑟夫环(数学解决)
- ios plist 权限访问大全
- HorizontalScrollView头部滑动
- ${pageContext.request.contextPath} :JSP取得绝对路径方法
- 解决IE浏览器兼容性问题:“JSON”未定义
- 微机原理之八大通用寄存器
- Unity低级本地插件接口--Low-level Native Plugin Interface
- ElemType是什么?
- NIO 02 阻塞式和非阻塞式[Socket]
- 如何实现一个线程安全的map?
- 安卓的4种动画
- express获取表单中的文件和其他数据(enctype=multipart/form-data)