File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes JSP not showing images whose physical path is fetched from mysql database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP not showing images whose physical path is fetched from mysql database" Watch "JSP not showing images whose physical path is fetched from mysql database" New topic
Author

JSP not showing images whose physical path is fetched from mysql database

Imdad Soomro
Greenhorn

Joined: Jul 15, 2009
Posts: 16
Dear All,
I am developing a book store web application where admin uploads the books and those books are displayed on the JSP Page. Admin inserts name, author and physical path of book image. All are stored in db and image is also saved on the location given in physical path. Image is uploaded using Apache commons library.
Problem occurs when records are displayed but image does not although image is physical present in the location. I have used several ways to display the image but none has worked. Although hard coded path displays the image. Following are few ways i have used in JSP file:

<%
ArrayList l = (ArrayList)request.getAttribute("books");
b = (Book)l.get(0);
String path = "C:\\Users\\tom\\workspace\\BooksLibrary\\WebContent\\"+b.getFilePath(); // b.getFilePath() returns "images/err.jpg"
%>
<img src=<%=path %> alt="image" width="100" height="150" />

I have also tried:
<img src="http:\\localhost:8080\BooksLibrary\<%out.println(b.getFilePath());%>" alt="image" width="100" height="150" />

I am using eclipse and images are saved at :
C:\Users\tom\workspace\BooksLibrary\WebContent\images\

Kind response will be appreciated.
Thanks
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
You will never, ever be able to access an image that is stored in a server using a path like c:\\..., you must understand that c:\\ is a local path related to your server and you are trying to access the image from a client that is not in the same machine. Let alone the security problems that has the fact that someone would be able just to access files directly in the server using a simple path...

You have to deploy the images in your server, just like your JSPs an access them the same way. For example if you have them under WebappRoot/web/images, then you can access them just as if they were a js file, a css or whatever.

If you have them in your server maybe you are just forgetting the context path. Other thing, that you have them in your workspace does not automatically mean that they are deployed in your server.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Sabarish Jaganathan, Your post was moved to a new topic. Please start your own topic for your own questions.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
Don't get me started about those stupid light bulbs.
 
subject: JSP not showing images whose physical path is fetched from mysql database
 
Similar Threads
Image display in jsp
image does not display on JSP page w/ Tomcat server
Not able to display images
Image Display problem
How to change the src attribute of embed tag