${pageContext.request.contextPath} works fine local, but shows blank live

戏子无情 提交于 2019-12-07 22:12:19

问题


Currently I am using

${pageContext.servletContext.contextPath}

or

${pageContext.request.contextPath}

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?


回答1:


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.

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.



来源:https://stackoverflow.com/questions/30443205/pagecontext-request-contextpath-works-fine-local-but-shows-blank-live

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!