0

I have the Servlet which creates the new images in webapp/images folder by ImageIO.write() method. Before starting the server this folder is empty.

This is JSP which should displays the images:

<figure>
    <img src="subimages/subimage_0.jpg" height="144" width="256">
</figure>

<figure>
    <img src="subimages/subimage_1.jpg" height="144" width="256">
</figure>

So I start my server, go through localhost:8080/puzzle and see nothing, but in the same time folder images contains all images I need. Refrashing the page didn't help. Then I restart my server, and JSP displays my images. Everything is ok, but can it displays my images without server's restarting?

I will be sooo thankful for any explanation or advice.

  • You mean you are restarting the Tomcat and you can see the images. Is this happening all the time? Or you tried only once? – S14321K Jun 02 '23 at 13:27
  • @S14321K When I am running the first time (when folder `images` is empty), I see nothing, but my servlet creates the images in that folder, so when I run the server next time everything is ok because the folder contains images before the server starts, but why JSP can't display images during first run, why it thinks like `images` folder is empty, servlet creates that images dynamically I don't get it – jackeylove17 Jun 02 '23 at 13:32
  • 1
    Do not save uploaded images in deploy folder! See abovelinked duplicate for in depth explanation why this is a bad idea. – BalusC Jun 02 '23 at 13:32
  • @BalusC ok, but how can I display the image in JSP in another way? for me only worked ` – jackeylove17 Jun 02 '23 at 13:34
  • It's also explained in a "See also" link in the abovelinked duplicate. – BalusC Jun 02 '23 at 13:34
  • @BalusC alright, thank you a lot, i am noobie here sorry for your time – jackeylove17 Jun 02 '23 at 13:35
  • @jackeylove17 you can point to tomcat folder instead of project folder. So that without redeployment you can fetch the images. – S14321K Jun 02 '23 at 13:40
  • @S14321K can you please give me an example, of how to display the image in this way in JSP? I have Tomcat in `D:/Tomcat/` folder and Project in D:/Workspace/Project – jackeylove17 Jun 02 '23 at 13:42
  • @jackeylove17 I think you must go through the link which is shared. There they have mentioned clearly. I can see this may help you https://stackoverflow.com/a/1812356/11962586 – S14321K Jun 02 '23 at 14:11

0 Answers0