This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript 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

Deployment issue

 
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
 
Author
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to use a relative path for your image, such as:
<img src="images/logo.gif">
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had same issue and I had raised the question in servlet-interest mailing list and got the same answer. Happy to note that I am not alone.
I was under the impression /images/... will resolve to <web-root-of-this-web-app>/images/...
while it is not the case. "/" always resolves to
<default-web-root-of-server>/....
But somehow I am convinced yet. I feel I am missing something and there should be a way that case 1 works. let me know if you hit upon anything.
 
Hari babu
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Karl Moss:
You need to use a relative path for your image, such as:
<img src="images/logo.gif">


Hi Karl,
If i use <img src="images/logo.gif">, it tries to get the logo.gif from images folder under "Myapp" folder, which i dont have b'coz "Myapp" and "images" are at same level.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hari,
U have to put the 'images' folder inside yr 'myApp' folder. Then u can use <img src="images/logo.gif"> statement.
Atanu

Originally posted by Hari babu:

Hi Karl,
If i use <img src="images/logo.gif">, it tries to get the logo.gif from images folder under "Myapp" folder, which i dont have b'coz "Myapp" and "images" are at same level.


[ April 25, 2002: Message edited by: Atanu Dey ]
 
Hari babu
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Atanu Dey:
Hi Hari,
U have to put the 'images' folder inside yr 'myApp' folder. Then u can use <img src="images/logo.gif"> statement.
Atanu

[ April 25, 2002: Message edited by: Atanu Dey ]


Hi Atanu,
If i put images folder in "Myapp" directory it will work, but what if i have another directory "module1" in my web folder and i want the same logo image in one of its JSP,then i should copy the images folder under module1 also, which is waste, as iam repeating the same set of files (here logo.gif). I want to have a single set of files
Thanks
 
Atanu Dey
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hari,
If u want to have one more directory 'module1' in the 'MyApp' directory and want to access the same logo.gif in a JSP file inside that 'module1' folder, just refer to the image like this:
<img src="../images/logo.gif">. Likewise u can have multiple JSPs in multiple folders accessing the same image file in 'images' folder.
Hope this will solve yr problem. let me know.
Atanu

Originally posted by Hari babu:

Hi Atanu,
If i put images folder in "Myapp" directory it will work, but what if i have another directory "module1" in my web folder and i want the same logo image in one of its JSP,then i should copy the images folder under module1 also, which is waste, as iam repeating the same set of files (here logo.gif). I want to have a single set of files
Thanks

 
I carry this gun in case a vending machine doesn't give me my fritos. This gun and this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic