Reputation: 7204
I have a war (foo.war) file that gets deployed to a tomcat installation, and tomcat properly sees the file and expands it out and I can access the site using http://localhost:8080/foo
, but for any path that uses a slash a the beginning (i.e. /bar/test.js
) it will try to reference that off of the http://localhost:8080
path instead of the http://localhost:8080/foo
path. Paths that don't start with a slash bar/test.js
work fine. I've been messing around with this for an hour or so googling around, but so far I haven't come up with anything. I'm not even sure what the correct steps are to debug this type of issue. Nothing is showing up in the logs related to this, and I've looked at the configuration files, but nothing has jumped out at me.
Any helpful pointers on what to look at to see why this is happening?
Edit: In response to some good points that other people brought up, it was my understanding originally that any path that started with a slash would be an absolute path and would be based off the host, but the answer to this question (Absolute path & Relative Path) stated otherwise which is why I asked my question.
Upvotes: 0
Views: 451
Reputation: 23535
Anything not starting with a /
is relative to the current location. Anything starting with /
is root to the host.
So, unless I missed something in your description the behavior you're seeing is correct.
...any path that started with a slash would be an absolute path and would be based off the host
Yes, that's correct.
You weren't asking for how to create the proper URLs that include the context root (foo
in your example), were you? In case you're using JSPs the answer would be here: https://stackoverflow.com/a/4764586/131929
<link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css" />
Personally I favor the JSTL <c:url>
tag.
<link type="text/css" rel="stylesheet" href="<c:url value="/css/style.css" />" />
Besides added the context root/path it offers a few more goodies.
Upvotes: 1