Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet forward JSP, image problem

 
Jaime Garcia
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, good solution
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic