"不允许加载本地资源:file:///C:....jpg";Java EE Tomcat [英] "Not allowed to load local resource: file:///C:....jpg" Java EE Tomcat

查看:40
本文介绍了"不允许加载本地资源: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. 我已经将图片存储到 c:images 文件夹并假设完整路径的名称是 c:imagesmypic.jpg
  2. 当我尝试检索它时,使用一些 Java 代码将 img src 属性设置为 <img src="c:imagesmypic.jps">
  3. 在浏览器控制台中我发现了这个错误 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 ?

推荐答案

sending tag <img src="c:imagesmypic.jpg"> 会导致用户浏览器访问图片从他的文件系统.如果您必须将图像存储在位于 c:images 的文件夹中,我建议创建一个 servlet,如images.jsp,它作为参数采用文件名,然后将 servlet 响应内容设置为image/jpg 然后从服务器位置加载图像字节并将其放入响应中.

sending tag <img src="c:imagesmypic.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆