• Post Reply Bookmark Topic Watch Topic
  • New Topic

variable in scriplet and declaration  RSS feed

 
Nelson Nadal
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The variable in declaration code is member variable(instance), isnt it? Then why is it said that when two user making requests to the same JSP can change the value of the same variable?
It also said that if I want the variable to be different for each request I should put it in scriplet code, this must be the instance or static?
Thanks again for enlightment....
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Variables created via a declaration are indeed created at the class level as instance variables. Since the container will share a single instance of the servlet created on behalf of your JSP (as other servlets) across threads, each thread executing the JSP will 'see' the same variables.
When the variable is created in a scriptlet, the declaration is within the body of a method and therefore has a unique (stack) instance for each thread.
hth,
bear
[ July 07, 2003: Message edited by: Bear Bibeault ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!