Including static user defined methods in servlets.
1 posts in topic
Flat View  Flat View

Posted By:   Sangita_kc
Posted On:   Saturday, March 2, 2002 08:49 AM

I want to know whether we can have static user defined methods (not overridden methods) in servlets. If so, how does it involves in servlet life cycle? Will it lead to session collapse or something like that? It runtime how will it react?

Re: Including static user defined methods in servlets.

Posted By:   neal_ravindran  
Posted On:   Saturday, March 2, 2002 05:23 PM

A Servlet is basically a Java class file generated from Java code written using all keywords available.
So the answer should be "yes you can define static methods".
for example see Jason Hunter's example code in which toHex() is static:


Static methods by definition, can be invoked before even a single instance of the class is constructed.
In other words, it exists before the servlet instance is created(beofre init() runs)

I did not understand why you would think a static method in servlet code would cause session collapse(I cannot picture that)
Maybe I am missing something(iow didn't get that:-) Could you kindly explain why you thought so!

To me the user session and a static method in code seem to have no relationship...unless maybe if the static method does something with the user session var(and nobody would)

Bottom-line:-static methods as utility methods is ok in servlets !

About | Sitemap | Contact