• Post Reply Bookmark Topic Watch Topic
  • New Topic

context and static parameters  RSS feed

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !!!
 
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Bartender
Posts: 4018
42
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.).
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!