Forums Register Login

context and static parameters

+Pie Number of slices to send: Send
Can anyboby tell me is there any difference between static and context variables? In the sense like : static variables are shared among objects, and context variables are shared among the servlets objects.


THANKS !!!
+Pie Number of slices to send: Send
 

static variables are shared among objects, and context variables are shared among the servlets objects.



I think there is some confusion here.
When we say static variables, it means that instances of that class do not have separate copies of that variable.
And there is no such thing as context variables, there are either context parameters or context attributes. The word context only specifies the scope and the life of the parameter or attribute.


Can anyboby tell me is there any difference between static and context variables?


Now can you reframe the above question so that it becomes more clear what exactly you want to know.
+Pie Number of slices to send: Send
 

static variables are shared among objects



Yes. When you define a static variable it belongs to class/interface it is defined. So no matter how many objects you created (in case of class) you get same value for all the instances. You could access static variable even without an instance (like ClassName/InterfaceName.Variablename).

and context variables are shared among the servlets objects.



Actually that's refered as Context Parameters, and yes they are shared by the web app which those parameters defined (those parameters are defined in web.xml and will bound to ServletContext at the deploy time/when the server restarts.).
yeah, but ... what would PIE do? Especially concerning this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1045 times.
Similar Threads
static instance variables
Getting problem in declaring static variable.
Sharing member variables in EntityBean instances?
FBNS:Question about Database Server design
question on static members
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 07:53:57.