JSP not showing images whose physical path is fetched from mysql database
Joined: Jul 15, 2009
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:
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 :
Kind response will be appreciated.
Joined: Apr 08, 2009
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.