This week's book giveaway is in the JDBC forum.
We're giving away four copies of Make it so: Java DB Connections & Transactions and have Marcho Behler on-line!
See this thread for details.
The moose likes Servlets and the fly likes super.init(...) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "super.init(...)" Watch "super.init(...)" New topic


Mohan Panigrahi
Ranch Hand

Joined: Sep 28, 2001
Posts: 142
I have read over and over again that super.init() method should be the first statement in
public void init(ServletConfig conf) {} method.
However even if I put some statements before super.init(), the servlet compiles and runs without a problem.
What could be the reason???
chanoch wiggers
Ranch Hand

Joined: May 24, 2001
Posts: 245
theres nothing in the java spec that can mandate that init() be called first and if not done compilation should fail. This is a convention which you are strongly encouraged to follow but you cannot be made to follow it. Remember that you could (but might not) run into problems if you depend on the servlet container's environment being set up correctly but dont wait for the servlet to be properly initialized

chanoch<p><a href="" target="_blank" rel="nofollow">Author of Professional Apache Tomcat</a></p>
Mohan Panigrahi
Ranch Hand

Joined: Sep 28, 2001
Posts: 142
Thanks chanoch, for the reply.
I understand that we should do super.init() to properly initialize the servletConfig variable of the super class. And if we do not initialize it properly, we can run into problems.
My next question is : What is the role of super.init() in setting up servlet container's environment, apart from initializing the super classe's servletConfig variable.
I agree. Here's the link:
subject: super.init(...)
It's not a secret anymore!