$ {pageContext.request.contextPath}在本地工作正常,但实时显示空白 [英] ${pageContext.request.contextPath} works fine local, but shows blank live

查看:428
本文介绍了$ {pageContext.request.contextPath}在本地工作正常,但实时显示空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前我正在使用

${pageContext.servletContext.contextPath}

${pageContext.request.contextPath}

在JSP页面上打印上下文路径.对于本地服务器来说,它工作正常,但是当我上线时,它会打印空白而不是实际路径.

to print the context path on the JSP page. It is working fine for the local server, but when I go live it prints blank instead of the actual path.

我可以打印请求端口号和请求方法,但不能打印上下文路径.

I am able to print the request port number as well as request method, but not the context path.

这是怎么引起的,我该如何解决?

How is this caused and how can I solve it?

推荐答案

将其部署到root时将发生这种情况.例如.在Tomcat中为ROOT.war或上下文路径为/. ${pageContext.request.contextPath}然后将解析为空字符串.

That will happen when it's deployed to root. E.g. as ROOT.war in Tomcat, or having a context path of /. The ${pageContext.request.contextPath} will then resolve to an empty string.

如果您实际上在浏览器的地址栏URL中看到一个上下文路径",那么当将Web应用发布到一个(较差的)第三方主机时,该情况可能会发生,而该第三方主机又将该Web应用实际部署为root并添加了上下文路径"指向该主机上的某些代理服务器.您可以通过检查响应标题中的Server条目来检查/确认.您最好与第三方主机联系,以获取有关如何从代理服务器获取有关上下文路径"的信息(也许它存在于请求标头中)的线索,或者寻找另一种不太便宜的第三方主机.

If you're actually seeing a "context path" in browser's address bar URL, then it can happen when the webapp is published to a (poor) 3rd party host which in turn actually deploys the webapp as root and adds that "context path" to some proxy server on that host. You could check/confirm that by checking the Server entry in the response headers. You'd best contact the 3rd party host for clues about how to obtain information about that "context path" from the proxy server (perhaps it's present in a request header), or look for a different 3rd party host which is less el cheapo.

这篇关于$ {pageContext.request.contextPath}在本地工作正常,但实时显示空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆