I have an html page that makes periodic AJAX calls to a servlet every 4 seconds. In the servlet, i write some information to a file and print some statements using System.out.println()
However, the writes to a file and the print statements get printed only once. shouldnt it be happening every time my page sends an AJAX request?
Here is the AJAX code:
$(document).ready(function() {
setInterval(function(){
$.get('Poller',
function(responseText) {
alert("response received: "+responseText);
var obj=jQuery.parseJSON(responseText);
$("div#key1").text("a");
$("div#val1").text(obj.Server1);
$("div#key2").text("b");
$("div#val2").text(obj.Server2);
$("div#key3").text("c");
$("div#val3").text(obj.Server3);
$("div#key4").text("d");
$("div#val4").text(obj.Server4);
setTimeout(function(){
},1500);
responseText="";
alert("response text now: "+responseText);
});
},4000);
});
And here is the code for my servlet file:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("new call");
//code write to file
}
The servlet documentation says that the service() method will call doget() function only for the first request from the client. Is it because of this issue that doget() gets called only once as opposed to every 4 seconds?