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.
You need to understand how HTTP and HTML work:
<img src="..."/>tagsSo, you need a servlet or JSP which generates the HTML page, containing all your
<img src="..."/>tags. Each of this tag should have the following form:And you need a second servlet, mapped to
imageServlet, which reads the bytes of the image identified by theimageIdparameter value from the file system, and write those bytes to the response output stream.