Reputation: 5518
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.
Upvotes: 2
Views: 452
Reputation: 1108712
I know there are some work arounds (like manually adding the context path onto the URL, using
<c:url>
, etc.
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.
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.
No. It's not servletcontainer's responsibility. Neither JspServlet
nor DefaultServlet
do this. It's the webapp's own responsibility (and the serveradmin's as far as applicable).
Upvotes: 4