Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Not allowed to load local resource: file:///C:....jpg" Java EE Tomcat

I'm trying to retrieve a picture from my file system after a good storage,(instead of putting it in the database I copy it to the disc and i put the path to the db)

  1. I had store the picture to c:\images\ folder and supposing that the name the complete path is c:\images\mypic.jpg
  2. when I try to retrieve it a set the img src attribute to <img src="c:\images\mypic.jps"> by using some java code
  3. in the browser console I found this error Not allowed to load local resource: file:///C://images//mypic.jpg

Question: how to fix these path problem ? where Should I store the pictures ? and from where should I retrieve them ?

like image 950
K.Ariche Avatar asked May 31 '14 12:05

K.Ariche


1 Answers

sending tag <img src="c:\images\mypic.jpg"> would cause user browser to access image from his filesystem. if you have to store images in folder located in c:\images i would suggest to create an servlet like images.jsp, that as a parameter takes name of a file, then sets servlet response content to an image/jpg and then loads bytes of image from server location and put it to a response.

But what you use to create your application? is it pure servlet? Spring? JSF?

Here you can find some info about, how to do it.

like image 190
T.G Avatar answered Sep 19 '22 08:09

T.G