Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

JSP and deployment

 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Below is my Web application structure ( i have shown the only the required files/ folders). Myapp,images,WEB-INF are at same level
web
Myapp
start.jsp
images
logo.gif
WEB-INF
web.xml

my start.jsp looks like this, where iam trying to display the logo image from images folder
<%
// do nothing other than showing the image
%>
<html>
<head></head>
<body>
<img src="/images/logo.gif">
</body>
</html>

The above start.jsp displays the image when i deploy this application as default ( i access it as http://localhost/). The image path ( when i check thru Image properties in IE ) will be http://localhost/images/logo.gif. But the problem comes when i give a name to the web application, say i give it as "mywebapplication" ( i access it as http://localhost/myapplication), In the case the image wont be shown. Still its path will be http://localhost/images/logo.gif, but actually it should have been http://localhost/mywebapplication/images/logo.gif. I want the image to be shown, but once it is deployed i dont want my JSP code to be changed whether it is deployed as default webapp or deployed with some contextName ( like mywebapplication or ourwebapplication etc.). Is my <img> tag in the above JSP is wrong or i need to do some configuration in web.xml.
Any help is appreciated
Hari
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Hari babu:
Below is my Web application structure ( i have shown the only the required files/ folders). Myapp,images,WEB-INF are at same level

my start.jsp looks like this, where iam trying to display the logo image from images folder

... But the problem comes when i give a name to the web application, say i give it as "mywebapplication" ( i access it as http://localhost/myapplication), In the case the image wont be shown. Still its path will be http://localhost/images/logo.gif, but actually it should have been http://localhost/mywebapplication/images/logo.gif.


It's because your image is linked like this:
<img src="/images/logo.gif">
the "/" in the beginning tells it to go to the root of the server. So if you keep it as
<img src="images/logo.gif">
It will always be relative to where you are -- and in the case of your /mywebapplication
it will look for file at /mywebapplication/images/logo.gif
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic