在“我的电脑"文件夹中的"JSP"页面上显示图像 [英] Show Image on JSP page from My Computer Folder

查看:96
本文介绍了在“我的电脑"文件夹中的"JSP"页面上显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用代码.但是,为什么网页从不允许访问任何本地文件.

I am trying to play with codes. However, why does Webpage NEVER allow the to access any local files.

表示如果您写

<img src="c:\ImageFolder\Angelica.jpg"/>

在jsp文件中,它将不起作用.

in the jsp file, it will NOT work.

为什么不呢?我可以从C盘中检索图像并显示在网页中吗?

WHY NOT? Is there a way for me to retrieve an image from my C Drive and display in webpage?

推荐答案

src属性用于引用源的相对路径或url,即源可以在您的Web容器内或由其他网站托管.您不能使用绝对路径作为源,因为您不能引用容器外部的文件.

src attribute of img tag is used to refer relative path or url of source i.e source can be inside your web container or hosted by some other website. You cannot use absolute path for source, as you cannot refer to files outside container.

作为一种变通方法,您可以创建一个servlet,该servlet可以从Web容器外部加载文件,然后将文件写入/流式传输到响应中.您将提供文件到servlet的路径,并且该servlet将为您提供文件.

As a work around, you can create a servlet that can load file from outside of your web container and then write/stream file to your response. You will provide path of file to the servlet and that servlet will serve the file to you.

假设如果您创建了一个用于提供文件名为"FileServlet"的文件的servlet,并且此FileServlet以"path"作为参数来获取文件,则img标签将如下所示:

Suppose if you create a servlet for serving file with name 'FileServlet', and this FileServlet takes 'path' as parameter to fetch file, you img tag will look something like this:

<img scr="FileServet?path=c:\\parentDirectory\file.jpg">

请参考: BalusC的File Servlet ,以进行详细的工作.

refer: File Servlet by BalusC for detailed working.

这篇关于在“我的电脑"文件夹中的"JSP"页面上显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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