Tomcat 7 上的 URL 丢失应用程序名称
我有一个在 Tomcat 7 上运行的 Java 应用程序。我希望我的应用程序的名称包含在 URL 中。例如:
http://localhost:8080/MyApp
我构建 WAR、部署,并且应用程序被正确访问。但是,我的所有 和
<a href="/myPage">Click Me</a>
是行不通的。链接最终是这样的:
http://localhost:8080/myPage
而不是
http://localhost:8080/MyApp/myPage
IsthereanywaytoconfigurationTomcattoaddtheapplicationnametolinksetc?如前所述,我不想从 URL 中删除应用程序名称(即使其成为根)。我知道有一些解决方法(比如手动将上下文路径添加到 URL 上,使用
等。但我想知道是否可以告诉 Tomcat 这样做。我想这是询问的地方,因为请求没有到达我的应用程序。如果重要的话,我正在使用 Spring MVC 和 Maven。
I have a Java application running on Tomcat 7. I want my application to have it's name in the URL. For example:
http://localhost:8080/MyApp
I build the WAR, deploy, and the application is accessed correctly. However, all of my <a>
and <form>
tags don't add the application name to the URLs. That is, doing something like:
<a href="/myPage">Click Me</a>
does not work. The link ends up like this:
http://localhost:8080/myPage
instead of
http://localhost:8080/MyApp/myPage
Is there any way to configure Tomcat to add the application name onto links, etc? As mentioned, I don't want strip the application name off of the URL (i.e. making it the root). I know there are some work arounds (like manually adding the context path onto the URL, using <c:url>
, etc. But I am wondering if Tomcat can be told to do this. I figure this is the place to ask, since the request isn't getting to my application. If it matters, I am using Spring MVC and Maven.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些不是解决方法。这些是解决方案您只是犯了一个错误,总是假设 Web 应用程序在域根上运行。最简单的解决方案 -imo- 是使用 HTML
。 href="https://stackoverflow.com/questions/3655316/servlets-browser-cant-access-css-images-when-doing-a-forward-to-a-jsp/3658735#3658735">此处。不。这不是 servletcontainer 的责任。
JspServlet
和DefaultServlet
都不会执行此操作。这是网络应用程序自己的责任(以及服务器管理员在适用的情况下)。Those are not workarounds. Those are solutions. You just made a mistake of always assuming that the webapp runs on the domain root. Easiest solution -imo- is using the HTML
<base>
. See also here.No. It's not servletcontainer's responsibility. Neither
JspServlet
norDefaultServlet
do this. It's the webapp's own responsibility (and the serveradmin's as far as applicable).