2

I am trying to display images on a JSP page. Two hyperlinks are used to display image.
One of them is as follows:

<a href="img/MyPic.jpg">Image</a>

When one of the links is clicked, the corresponding image is displayed. In the above case, MyPic.jpg is saved in web\img\MyPic.jpg(Inside the project folder).

In the other case, I saved the image in local disk.

E:\img\MyPic.jpg

and I tried the following code:

<a href="E:/img/MyPic.jpg">Outside image</a>
and
<a href="file:///E:/img/MyPic.jpg">Outside web</a>

But this link is not working and I can't access the image.

UrsinusTheStrong
  • 1,239
  • 1
  • 16
  • 33
  • You need to realize that you're writing a web application, where everything that is displayed by the browser comes from HTTP requests sent to a server. Imagine your web server is your machine, located in India, and the browser runs on my machine, running MacOSX, in France. How could my MacOSX machine possibly access an image located on your machine with the path `file:///E:/img/MyPic.jpg`?The web server serves resources located in your webapp, over HTTP. It doesn't serve files out of the webapp, and certainly not using the file protocol. – JB Nizet Apr 09 '16 at 10:48
  • @JB Nizet if i save a lot of documents in my application, it will become too large. So, is there any solution to save it outside? is there any solution to get its resourse path to my project? – Harikrishnan Apr 09 '16 at 11:16
  • http://stackoverflow.com/questions/2340406/how-to-retrieve-and-display-images-from-a-database-in-a-jsp-page – JB Nizet Apr 09 '16 at 11:44
  • @ JB Nizet i tried it using aliases in context.xml. But it didn't work – Harikrishnan Apr 12 '16 at 06:30

0 Answers0