File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Servlet forward JSP, image problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet forward JSP, image problem" Watch "Servlet forward JSP, image problem" New topic

Servlet forward JSP, image problem

Jaime Garcia
Ranch Hand

Joined: Jan 07, 2003
Posts: 38
I am using servlets for db operations, etc. and jsp for presentation. But, when I do a forward from a servlet to a JSP, all the image, css, etc. paths keep with the servlet URL (the browser dose not know about the forward, i guess).
I used a propertie to set this path in the jsp, so I have <img src="<%=prop.IMG_PATH%>/x.gif>, but it becomes dificult to edit the Graphical design, so, Is there a better way to do this and keep the relative path of the images ?.
Eelco den Heijer
Ranch Hand

Joined: Jan 17, 2002
Posts: 61
Hi, I recognize your problem, I've encountered it myself a few times. I can only say that the solution I came up with is more or less the same as the one you have (keeping the path from the web context stored in a constant or property)... It seems that if you do a forward every notion of 'current location' in the web app is gone....

== <br />Rgrds,<br />Eelco<br /> <br />SCJP, SCJD, SCBCD, SCWD, SCEA
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
HTML provides a BASE tag that you could put in your JSP to define where resouces such as CSS and images come from. A BASE tag goes in the HEAD area of an HTML page like:

now any relative url for an image will be interpreted by the browser as coming from that base.
Jaime Garcia
Ranch Hand

Joined: Jan 07, 2003
Posts: 38
Thanks, good solution
I agree. Here's the link:
subject: Servlet forward JSP, image problem
It's not a secret anymore!