1,105,402 Community Members

How to use java&jsp

Member Avatar
szagarella
Newbie Poster
2 posts since Mar 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
Philippe.Lahaie
Posting Whiz
376 posts since Oct 2007
Reputation Points: 42 [?]
Q&As Helped to Solve: 60 [?]
Skill Endorsements: 9 [?]
 
0
 

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

Member Avatar
szagarella
Newbie Poster
2 posts since Mar 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

Member Avatar
Philippe.Lahaie
Posting Whiz
376 posts since Oct 2007
Reputation Points: 42 [?]
Q&As Helped to Solve: 60 [?]
Skill Endorsements: 9 [?]
 
0
 

read this

<%= a-java-expression %>
<!--or-->
<jsp:expression> a-java-expression </jsp:expression>
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: