wood burning stoves 2.0*
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
Author

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
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
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.
Bill
Jaime Garcia
Ranch Hand

Joined: Jan 07, 2003
Posts: 38
Thanks, good solution
 
jQuery in Action, 2nd edition
 
subject: Servlet forward JSP, image problem
 
Similar Threads
jsp page can't find the applet
Error 400: Invalid path /main was requested
In struts Can't display dynamic content using "include"?
Why this code to get Init Param in JSP not work?
related to .do and .faces