Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP - Java and Javascript 'for' loop problem  RSS feed

 
Kathy Graham
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JSP file with inlaid java 'for' loop. I am now writing a javascript function with a 'for' loop. The javascript function is supposed to be executed when a button is clicked in the jsp page.

The problem is after I wrote the 'for' loop for the javascript function, eventhough I haven't clicked the button to execute the javascript, the java 'for' loop gets executed ...

Any help is really appreciated. Thanks!
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kathy,

You may want to read the following article (written by our esteemed moderator, Bear Bibeault):
http://www.javaranch.com/journal/200510/Journal200510.jsp#a1

The thing to remember is that the server side Java/Jsp code and the client side Javascript code run in two different worlds. By the time your Javascript and HTML are rendered in the user's browser, the JSP/Java code is done executing.

If, from your browser, you click on View -> HTML Source, you will see what the JSP/Java code produces. This output gets loaded into the browesr's memory and is then interpreted as HTML and/or Javascript.

The article will do a better job of explaining this than I just did.

-Ben
[ May 19, 2006: Message edited by: Ben Souther ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!