Reputation: 1174
How can I deploy an application to tomcat in Intellij as ROOT.war?
I've 2 applications deployed both have pages with code like this:
<c:url value="/someLink"/>
The application deployed on context path /
gives the following result:
/someLink
While the other application deployed on context path /something
gives the following result:
http://localhost:8080/something/someLink
How can I make sure that this also gets done for the application deployed on context path /
?
So the end result looks like this
http://localhost:8080/someLink
Upvotes: 2
Views: 1104
Reputation: 1174
I've found a solution to this problem.
The problem was that Intellij deployed the application under the context /
.
When using the <c:url>
-tag with the following value <c:url value="/someLink"/>
The <c:url>
-tag changes the link to //someLink
.
When URL is put on the response it doesn't prefix it with the hostname.
The way I solved it was by adding a context.xml file in the META-INF directory of the war with the following contents:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="" />
This causes Intellij to deploy the application under the context ""
instead of "/"
.
The <c:url>
tag than converts the link to /someLink
and puts in the response including the hostname.
You'll also have to make sure that the war you deploy from Intellij is named ROOT.war to make it work.
Upvotes: 1
Reputation: 31906
I'm not sure why when in the root context you are getting different results than when in a named context. For me, the JSTL <c:url>
has always given a relative path, regardless of whether its the root context or a named context. I just tested in Tomcat 7 to be sure. Apparently there is something different in the JSTL implementation you are using that is causing the inconsistent results.
The JSTL 1.2 Specification is ambiguous as to what <c:url>
implementations should do. From section 7.5:
The URL must be either an absolute URL starting with a scheme (e.g. "http:// server/context/page.jsp") or a relative URL as defined by JSP 1.2 in JSP.2.2.1 "Relative URL Specification"
I recommend you take a look at the answer for Accessing the full url, including hostname with jstl That can tell you how to get the fully qualified URL. You may need to make adjustments (i.e. see of it is fully qualified before you prefix the server URL) to compensate for the fact that your <c:url>
implementation behaves differently in the root context than the named context. Ultimately, the easiest thing would be to write your own tag that handles all this (i.e. that wraps the other tags).
Upvotes: 0