• 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

JSP Declarations

 
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear all,
If we use jsp declaration :
<%! int A = 0; %>
Does it mean that we use variable A like static variable?
thanks
daniel
 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not static, rather like an instance variable. Check out the generated servlet code, you will notice that variables declared with <%! are declared as instance variables in the generated class. As opposed to variables declared in a scriptlet <%...%>, which become local to the _jspService method.
To declare static variables, you must explicitly declare the variable with the static modifier.
 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello Daniel,
if i understood you from your question, you may be thinking that since a single object is usually instantiated from the translated servlet of the jsp and such an object is shared among users, then the declared variable is also shared among users "like a static variable".... In a way, but such likeness is not safe to think of because if the servlet engine deems it necessary to creates many objects from the servlet then "like a static variable" will no longer hold.
[ March 14, 2003: Message edited by: boyet silverio ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic