My problem is that when I upload an image from one jsp and I go to another jsp which should show the image uploaded it doesn't show it. The image is uploaded and saved in my server, and I reference the correct path but for seeing the image I just need to restart tomcat. Here is my uploader servlet(I think that it works correctly because the image is saved):
// Get file from form
Part part = request.getPart("cartel");
// Path
String ruta_local = getServletContext().getInitParameter("local_path");
String img_dir = getServletContext().getInitParameter("img_directory");
// Image name
String fileName = extractFileName(part);
// Add random number to image name
Random rand = new Random();
int random_numbers = rand.nextInt(1000);
fileName = NameOrExtension(fileName, "nombre") + String.format("%03d", (random_numbers))
+ "." + NameOrExtension(fileName, "extension");
request.getSession().setAttribute("foto", fileName);
// Final path
String cartel_path = ruta_local + File.separator
+ img_dir + File.separator + fileName;
File cartel = new File(cartel_path);
// File write
try (InputStream input = part.getInputStream()){
Files.copy(input, cartel.toPath());
input.close();
}
The images are saved in my img-carteles forlder which is in WebContent folder, and when I try to show an image knowing his name I use:
<img class="card-img-top" src="img-carteles/image_name" alt="Card image cap">
So I think that is a tomcat's rendering issue. Question: How can I show and uploaded image not having to restart tomcat?