“Not allowed to load local resource: file:///C:…jpg” Java EE Tomcat

后端 未结 8 1473
忘了有多久
忘了有多久 2020-11-29 06:36

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)

相关标签:
8条回答
  • 2020-11-29 07:07

    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.

    0 讨论(0)
  • 2020-11-29 07:09

    The concept of http location and disk location is different. What you need to do is:

    1. for uploaded file summer.jpg
    2. move that under a known (to the application) location to disk, e.g c:\images\summer.jpg
    3. insert into db record representing the image with text summer.jpg
    4. to display it use plain <img src="images/summer.jpg" />
    5. you need something (e.g apache) that will serve c:\images\ under your application's /images. If you cannot do this then in step #2 you need to save somewhere under your web root, e.g c:\my-applications\demo-app\build\images
    0 讨论(0)
提交回复
热议问题