Forums Register Login

variable in scriplet and declaration

+Pie Number of slices to send: Send
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....
+Pie Number of slices to send: Send
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 ]
money grubbing section goes here:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 828 times.
Similar Threads
Doubt in static...
Marcus Green test1 Q16
Counting the number of hits on a link
Declaration
JSP basics
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 23:30:37.