I have a JSP page with following structure:
<input type='file' id='logo' />
<iframe src='view?media=logo'></iframe>
what I am trying to do here is to have user select an image and then I will upload it to a directory inside "WEB-INF" on the server. I have successfully implemented the server side of this meaning that I can see the new image copied to the destination folder. however I need to be able to show the image to the client. Since the image is in "WEB-INF" folder i can not do it by using an 'img' element and manipulating it's 'src' attribute. So I have implemented another servlet with URL pattern 'view'. This servlet receives the media which client is asking for (in this case 'logo') and use following code to forward to page to requested resource:
String media = request.getParameter("media");
String location = FileManager.getView(media);
getServletContext().getRequestDispatcher(location).forward(request, response);
So if everything goes as planned the recently uploaded image should be shown inside the iframe.
The problem is that ifram keeps showing the old images associated with my request but when i right click on the image and choose 'open in a new window' I see the corrected image.
I did some research and found out that this problem is somehow related to browser chaching the images and the solution suggested wast to add a random number at the end of 'src' attribute:
<img src='logo.png?random=klafjeiej3qk213 />
Though I can not apply this fix to my problem because images are stored inside WEB-INF and I use a servlet to retrieve them.
Is it possible to solve this caching problem (If it is a caching problem) ?