Start New Discussion Reply to this Discussion How to use java&jsp
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
szagarella
Newbie Poster
2 posts since Mar 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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.
Philippe.Lahaie
Posting Whiz
360 posts since Oct 2007
Reputation Points: 103
Solved Threads: 54
Skill Endorsements: 4
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.
szagarella
Newbie Poster
2 posts since Mar 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
read this
<%= a-java-expression %>
<!--or-->
<jsp:expression> a-java-expression </jsp:expression>
Philippe.Lahaie
Posting Whiz
360 posts since Oct 2007
Reputation Points: 103
Solved Threads: 54
Skill Endorsements: 4
© 2013 DaniWeb® LLC
Page generated in 0.0635 seconds
using 2.68MB