• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A very simple question: not able to understant: Pl help!!

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends,
According to JSP specs, variables are declared with the following syntax:
<%! name=value %>
How come the code below which i by chance modified from wrox book works perfectly on java web server. It should give compilation erorr:
<html>
<body>
<% int i = 1; %>
<% for (int x=0; x<5; x++) { out.println("value of i is: is :"+ i); } %>
</body>
</html>
Please tell me the reason. It would be a great help.
thanks a lot in advance
sudeepa
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sudeepa Basu,
Initially you have declared it as a global(instance) variable <%! int i = 0;%>, hence they are shared between different invokation of same jsp.
You have changed it to local variable <% int i = 0;%>, hence its still working. Now the variable i is local variable for method _jspService ( ...), which you would get when jspengine converts your jsp to java file.
Hope this helps,
Vijay
[This message has been edited by vijay kashyap (edited August 29, 2001).]
 
Sudeepa Basu
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot vijay.
I got it!
 
reply
    Bookmark Topic Watch Topic
  • New Topic