简体   繁体   English

Tomcat向URL添加上下文路径

[英]Tomcat adds context-path to urls

In my application every link generated is surrounded by response.ecodeURL. 在我的应用程序中,生成的每个链接都被response.ecodeURL包围。 On some servers encodeURL adds the context-path to the URL. 在某些服务器上,encodeURL将上下文路径添加到URL。

The application is named "appl". 该应用程序名为“ appl”。 Creating a link /a/b/c.jsp creates on DEV-system the url /a/b/c.jsp, on Prod it creates /appl/a/b/c.jsp 创建链接/a/b/c.jsp在DEV系统上创建URL /a/b/c.jsp,在Prod上创建/appl/a/b/c.jsp

The tomcat is behind an Apache Webserver which connects via ajp, not sure if thats a relevant fact. tomcat位于通过ajp连接的Apache Web服务器的后面,不确定那是否是一个相关事实。

EDIT: The Webserver isn't relevant. 编辑:Web服务器是不相关的。 I tried going directly on port 8080 and the same happend again. 我尝试直接在端口8080上运行,再次发生了同样的情况。

<c:url> always pre-pends the context path to URLs: this is standard practice and should always be done. <c:url>始终将上下文路径附加到URL:这是标准做法,应始终这样做。 If you are using <c:url> then you shouldn't add your own prefix. 如果使用的是<c:url>则不应添加自己的前缀。 Also note that <c:url> runs the URL through HttpServletResponse.encodeURL for you. 还要注意, <c:url>通过HttpServletResponse.encodeURL为您运行URL。 That method adds URL-based session-tracking information (eg the ";jsessionid" path parameter) if appropriate. 该方法在适当的情况下添加基于URL的会话跟踪信息(例如“; jsessionid”路径参数)。

You should always add the context prefix to all URLs, whether you use something like <c:url> or do it yourself. 无论您使用的是<c:url>类的东西,还是您自己做,都应始终将上下文前缀添加到所有URL。 You just shouldn't do both. 您不应该两者都做。 When you use the ROOT context, the context path with be "" (ie empty string) and nothing will be pre-pended to your URLs. 当您使用ROOT上下文时,上下文路径为"" (即空字符串),并且URL之前不会添加任何内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM