Hi at all.
I'm a new user of jsp and I've a problem. I would execute certain operations every X seconds in my jsp project like check data into mySql DB; I use a TimerTask java class and it's ok. But if I would update the UI inside the run method, eclipse signs me an error ("Cannot refer to a non-final variable out inside an inner class defined in a different method"). The code is here:
<div style="text-align: right; font-size: 12px; padding-top: 400px;">
<%!
int i = 0;
boolean refresh = false;%>
<%
TimerTask myTimerTask = new TimerTask() {
public void run() {
System.out.println("timer " + i);
i++;
if (i == 3) {
System.out.println("OK");
this.cancel();
out.println("UPDATE UI!"); /* <-- error */
}
}
};
Timer myTimer = new Timer();
myTimer.schedule(myTimerTask, 0, 2000);
%>
</div>
How can I resolve this little problem?
Thanks a lot
Salvo