从 servlet 输出图像文件
如何在 servlet 中提供存储在硬盘驱动器上的图像?
例如:
我有一个图像存储在路径 'Images/button.png'
中,我想在 URL file/button.png
的 servlet 中提供该图像。
How to serve an image, stored on my hard drive, in a servlet?
For Example:
I have an image stored in path 'Images/button.png'
and I want to serve this in a servlet with the URL file/button.png
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是工作代码:
Here is the working code:
/file
url 模式response.getOutputStream()
Content-Type
标头到image/png
(如果只是 png)/file
url-patternresponse.getOutputStream()
Content-Type
header toimage/png
(if it is only pngs)这是另一种非常简单的方法。
Here's another very simple way.