• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

image does not display on JSP page w/ Tomcat server

 
Nina Anderson
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a web application that does the following:

1) User uploads an image.
2) Application saves this image is a local directory on the server.
ex: C:/Users/684/Profile/images/_DSC0034.jpg
3) Application stores the newly created image path in the database.
4) Application displays the image on a web page using the path from the db:
ex: C:/Users/684/Profile/images/_DSC0034.jpg

However, in the last step where the application trys to display the image, the image FAILS to display. This used to on a Websphere server. I've moved to a Tomcat server and this does not work anywmore.

Why can't Tomcat display the actual image paths. How can I get this to work again?

Here's my code:

<img src="C:/Users/684/Profile/images/_DSC0034.jpg" name="business_images" width="100" height="130"/>

PLS...HeLP!
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nina Anderson:
PLS...HeLP!


In an effort to help everyone get the most from our forums, we've compiled a
list of tips for asking questions here. You can find the list in our
FAQ section here.
In particular please see:
UseRealWords

Abbreviations such as "u" or "ur" in
place of "you" and "you are" or "you're" confound language translation software making
it hard for our non-English speaking members to read your posts.
"plz" is not a word in the English language.

Again, welcome to JavaRanch and good luck with your question.
-Ben
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<img src="C:/Users/684/Profile/images/_DSC0034.jpg" name="business_images" width="100" height="130"/>


You're link is pointing to a file on the local machine.
This will only work if you're using a browser on the same machine that hosts the webserver.

You'll need to either move the file to a location within your webapp or build a servlet that can stream images from locations outside of it.
 
Nina Anderson
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I move my image files to the server root context like you suggested and the images is still not displaying.

In my userProfile.jsp, I tried the following with no success:

1.
<img src="Users/684/Profile/images/_DSC0034.jpg" name="business_images" width="100" height="130"/>

2.
<img src="/Users/684/Profile/images/_DSC0034.jpg" name="business_images" width="100" height="130"/>

3.
<img src="../Users/684/Profile/images/_DSC0034.jpg" name="business_images" width="100" height="130"/>

4.
<img src="../../Users/684/Profile/images/_DSC0034.jpg" name="business_images" width="100" height="130"/>


Here is my project hierarchy:

What am I doing wrong??




[BSouther: Added UBB CODE tags]
[ January 16, 2008: Message edited by: Ben Souther ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
Nina Anderson
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops...hierarchy did not come out right:

-> WEB-INF
- Users
- 684
- Profile
- images
- _DSC0034.jsp
- web
- Common
- header.jsp
- footer.jsp

- Images
- bkgrnd.gif
- logo.jpg

- Search
- UserProfile.jsp
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you saying that the Users directory is under WEB-INF?
 
Nina Anderson
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes...the "Users" folder is under WEB-INF.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That cannot work. The server will not serve anything under WEB-INF -- that's a protected region. Move all client-referenced resources (images, style sheets and script files) out of WEB-INF.
 
Nina Anderson
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, disregard my last comment. The "Users" folder IS outside WEB-INF folder. It is under the "WebRoot" folder.

This used to work fine. Why is it not working with Tomcat?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We still don't know what you structure is. The chart you posted isn't useful without indentation. Please go back and fix it by enclosing the folder chart in UBB code tags and adding the proper indentation.

The only reason it wouldn't work in Tomcat is if the URL is incorrect.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take the time to post the directory structure correctly.

I added UBB Code tags to your first directory listing which made the indents show up. From that listing, it appears that the Users directory is under (inside) WEB-INF which, as Bear said, won't work.

If you need help getting an accurate print out of your directory structure see:
http://faq.javaranch.com/java/HowToCopyEnvironmentVariablesAndDirectoryStructures
 
Nina Anderson
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eureeka!!!

This worked after all:

<img src="../../Users/684/Profile/images/_DSC0034.jpg" name="business_images" width="100" height="130"/>

I found that Right-Clicking on the light red 'x' on the non-displayed image and selecting on the 'properties' actually showed the path the server was trying to display. So, that helped me debug to get it to the right location.

Thanks for your help.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<img src="../../Users/

This is a bad bad idea. Your URL is page-relative and is fragile and will break not only if any structure gets moved around, but even if you address the page in a different way (as the result of a forward or include, for example).

I strongly urge you to pay attention to the posts that have been made and adopt best-practice server-relative URLs.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
I strongly urge you to pay attention to the posts that have been made and adopt best-practice server-relative URLs.


+1

See:
http://faq.javaranch.com/java/ResourceUrlProblems
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic