java 谁能解释一下这个 pageContext.request.contextPath 是做什么的?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28340995/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can anyone explain what this pageContext.request.contextPath does?
提问by user3931813
can anyone explain what will this pageContext.request.contextPath does?it would be helpful if you give an example.Thanks in advance.
谁能解释一下这个 pageContext.request.contextPath 会做什么?如果你举个例子会很有帮助。提前谢谢。
回答by Kamlakant Shukla
${pageContext.request.contextPath}
is an EL expression equivalent to the JSP expression <%= request.getContextPath() %>
.
${pageContext.request.contextPath}
是等效于 JSP 表达式的 EL 表达式<%= request.getContextPath() %>
。
It is recommended to use ${pageContext.request.contextPath}
instead of hard-coding your context path.
建议使用${pageContext.request.contextPath}
而不是硬编码您的上下文路径。
E.g. <a href="${pageContext.request.contextPath}/info/page.html">Link</a>
is better than <a href="http://abc.xyz.com/info/page.html">Link</a>
例如<a href="${pageContext.request.contextPath}/info/page.html">Link</a>
比<a href="http://abc.xyz.com/info/page.html">Link</a>