This week's book giveaway is in the Cloud forum.
We're giving away four copies of The Business Blockchain and have William Mougayar on-line!
See this thread for details.
Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP Declarations

 
Fisher Daniel
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
  • 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
 
Mark Howard
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • 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.
 
boyet silverio
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic