“不允许加载本地资源:file:/// C:.... jpg” Java EE Tomcat [英] "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)
- 我已将图片存储到c:\ images /\\文件夹中,并假设完整路径的名称为c:\ imagesi \ _ypyp.jpg
- 当我尝试检索它时,将img src属性设置为
< img src =c:\ images\mypic.jps>
在浏览器控制台中使用一些java代码 - 我发现此错误
不允许加载本地资源:file:/// C:// images // mypic.jpg
- I had store the picture to c:\images\ folder and supposing that the name the complete path is c:\images\mypic.jpg
- when I try to retrieve it a set the img src attribute to
<img src="c:\images\mypic.jps">
by using some java code - 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 ?
推荐答案
发送标签< img src =c:\\ \\ images\mypic.jpg>
会导致用户浏览器从他的文件系统访问图像。
如果你必须将图像存储在位于 c:\ images /
的文件夹中,我建议创建一个像images.jsp这样的servlet,作为参数取名一个文件,然后将servlet响应内容设置为image / jpg,然后从服务器位置加载图像的字节并将其放入响应。
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.
但你用什么创建你的申请?它是纯servlet吗?弹簧? JSF?
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.
这篇关于“不允许加载本地资源:file:/// C:.... jpg” Java EE Tomcat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!