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

well if the first 2 System.out.println() dont launch errors than i would try being consistant and using "System." on the third also.

well if the first 2 System.out.println() dont launch errors than i would try being consistant and using "System." on the third also.

The problem is the "System.out" print the result on my eclipse console and NOT in the html page. I would update the html page content.

read this

<%= a-java-expression %>
<!--or-->
<jsp:expression> a-java-expression </jsp:expression>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.