wood burning stoves 2.0*
The moose likes Servlets and the fly likes Servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlets" Watch "Servlets" New topic
Author

Servlets

Lalit Kapoor
Greenhorn

Joined: Jun 06, 2004
Posts: 20
Hello
I just want to know the concept behind using super.init(config) in the init() method of an Http Servlet. If GenericServlet class implements the ServletConfig interface, then what is the need of using the init() method of GenericServlet class.

Thanks
lalit
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 635
Hi Lalit,
if you override following method in your servlet then a config object will be created by server and will be assigened to config variable defined in this method
init(ServletConfig config)
{
}


this object can be used in doget or dopost method,but as it is local to
your init method it is must to initilize config variable of generic servlet
so that it will be useful in other methods,and this is done by calling super.init(config)...

hope this helps
Cheers
Praful


All desirable things in life are either illegal, banned, expensive or married to someone else !!!
Lalit Kapoor
Greenhorn

Joined: Jun 06, 2004
Posts: 20
Hello Praful,
I have seen the declaration of GenericServlet class but there is no instance varible name config or something else where the reference to the ServletConfig object passed as parameter to the init() method can be saved. Also, GenericServlet class implements the ServletConfig interface so the abstract methods, such as getInitParameter() etc., declared in the ServletConfig interface are automatically available in the subclasses that extends HttpServlet class.
That's why i am a bit confused about it..

Please explain this concept in detail about how and where the reference is saved...

Lalit
Rishi Tandon
Greenhorn

Joined: Oct 23, 2002
Posts: 17
I just want to know the concept behind using super.init(config) in the init() method of an Http Servlet.


A convenience method ( GenericServlet.init() ) which can be overridden so that there's no need to call super.init(config).
Instead of overriding init(ServletConfig), simply override this method and it will be called by GenericServlet.init(ServletConfig config). The ServletConfig object can still be retrieved via getServletConfig().


Rishi Tandon<br />SCJP 1.2<br />SCBCD
Lalit Kapoor
Greenhorn

Joined: Jun 06, 2004
Posts: 20
I read on a site that:
The default implementation of the init() method stores the ServletConfig object for use by the methods in the ServletConfig interface.

How is it possible that the methods of ServletConfig interfaces will be implemented using the reference of its own object?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlets