Hi
all,
I am
trying to properly use paths to images, links and what not within my "outside"
web application. I will also have the inside and admin applications deployed
in the same one web container (Orion App Server). Originally, I would ALWAYS
do the following for links and images:
<img
src="/images/image.gif">
<a
href="/path/page.jsp">click</a>
<a href="<%= contextPath
%>/path/page.jsp">Click</a>
where <%= contextPath %> is set to:
request.getServletPath().substring(0,
request.getServletPath().lastIndexOf("/"));
A
few problems are occuring. First, when deploying one web-app to the "root" /,
and another to /inside, and the last to /admin, in the /inside or /admin
web-apps, when I refer to <img src="/images"> it appears to look in the
ROOT web application, images folder. Obviously, this won't work..unless
ofcourse the right image is in the root application. But I don't want one
web-app to rely on another deployed apps paths for any resources..all must be
relative to its own web-app so it can be deployed as a stand-alone app. I
would guess this is not all that uncommon of a way to deploy (and develop)
web-apps?
So
now, my thinking was since each web-app runs in its own context, and I have 3
(/, /inside and /admin), that using the <%= contextPath %> in every link
and img, would work. However, as I have found out, when a page exists in say
/prdoucts/index.jsp, the <%= contextPath %> returns http://localhost/products so that
ALL my links are now starting off from that location. What I really want to do
is have some sort of variable in EVERY link and img that references the
WEB-APP root location, and not the current path a page is in. Is there a way
to get the specific web-application root from a page running within that
web-app? Also, is it required to use <img src="./images/image.gif"> when
referring to the images dir from the ROOT dir of any given web-app? If I use
the /images, as i said above, it alwyas navigates to the / context web-app,
unless the current web-app is the only one running.
I
guess what I am really looking for is the proper way to handle paths to
resources from within JSP pages (and servlets) that stick to the web-app its
running in, yet somehow using a common way to do this to guarantee all links
and resources follow this same path.
Thanks.