Image upload and update

Asked

Viewed 271 times

0

I have a javaEE application where one of the requirements is to upload an image used for the user profile.

Everything you’re accomplishing so far: 1. Selects the image to be edited (Cut, Rotate, etc.); 2. The photo is passed as Base64 to the Servlet; 3. The image is converted to a png file and saved to a directory [media/pic/example-img-hash-name.png]; 4. Saves the image name in the user database; 5. Returns the image name and changes the "src" attribute of the image with javascript;

So far so good, but the image does not update. I also try to access the image through the link and can not. Only after restarting the server the new image is loaded.

Is that a? web.xml server configuration? I’m using Intellij IDEA + Tomcat

1 answer

0


In the SRC attribute of the IMG TAG, insert a variable that we call "no-cache" identifier. generates a random number that will change with each request. So the cache of both browser and Servlet will not answer the cache but the correct query.

EX:

I hope I’ve helped.

Hug!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.