Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Servlet forward JSP, image problem

 
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 ?.
 
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....
 
Author and all-around good cowpoke
Posts: 13078
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
 
I don't even know how to spell CIA. But this tiny ad does:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic