Having some trouble refreshing the image, i have a script running in the background updating the image and i want to display the new image every X seconds, but when i run in browser the image is not refreshed
Anyone got any ideas?
<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1\>
<title> Title </title>
<script>
var image;
var imgBase="images/test.jpeg"
function count(){
image.src=imgBase;
}
function init(){
image = document.getElementById("image");
if( image ){
setInterval("count()",1000);
}
}
window.onload = init;
</script>
</head>
<body>
<img src="images/test.jpeg" id="image">
</body>
</html>
The web-application has the following directory tree ..
.
├── Home.jsp
├── images
│ ├── test.jpeg
├── META-INF
│ └── MANIFEST.MF
├── style.css
└── WEB-INF
├── classes
│ └── test
│ └── my
│ └── new
│ └── package
│ └── Test.class
├── lib
└── web.xml
9 directories, 10 files
Web console does not show any errors retriving image, but it does not refresh?
[00:53:15.896] GET http://host:8085/Servlet/Display?config=L1 [HTTP/1.1 200 OK 2ms]
[00:53:16.419] GET http://host:8085/Servlet/images/test.jpeg [HTTP/1.1 200 OK 2ms]
Appreciate any help, thanks!
The browser is showing the image from the browser cache.
A workaround is to request the image using an unique request parameter (e.g. a timestamp), so that the browser is forced to actually send a fresh new HTTP request instead of showing the image from the browser cache.
Note that this concrete problem has nothing to do with servlets. Even more, putting HTML code straight in a servlet class is a poor practice. HTML code belongs in a JSP file (and Java code in a servlet class).