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 !