Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
512 views
in Technique[技术] by (71.8m points)

java - Retrieve images from a folder outside web root folder using servlet

I'm trying to create a small servlet that uploads images and is able to retrieve them in a different page as a slideshow.

I'm able to save them outside the WebApp folder, but while retrieving them I need them to be a part of a JSP which will have other content, apart from the images. Currently, I'm using BufferedImage and ImageIO classes to stream the images one at a time.

BufferedImage image = ImageIO.read(new File("D:"+file.getName()));
ImageIO.write(image, "jpg", response.getOutputStream());

The file is checked to be a JPEG file type earlier in the code.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

them I need them to be a part of a JSP which will have other content,

Use image tag in JSP

<image src="/context-root/YourServlet?param=value" alt="blah blah"/>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...