Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help needed in understanding some code

Status
Not open for further replies.

786snow

Programmer
Nov 12, 2006
75
0
0
Hi,
I am new to java servlet. I am trying to understand this code. Is init() function in java servlet is like a constructor it gets executed with out having to call that function.? and what is super.init, here i believe they are calling the init() function of the parent class?



public class EDocsServlet extends BaseServlet
{
public void init()
{
super.init();
customerAccessOnly = false;
}

protected RequestProcessor getRequestProcessor(Log log)
{
return new EDocsRequestProcessor(log);
}

protected WebController getWebController(EjbController ejbController, Log log)
{
return new EDocsWebController(ejbController, log);
}

protected EjbController getEjbController(Log log)
{
return new EDocsController(log);
}

}
 
Hi

You will have to specify what [tt]BaseServlet[/tt] is. I assume that it extends the [tt]HttpServlet[/tt] class. If so, then the [tt]init()[/tt] method overrides the [tt]GenericServlet.init()[/tt] method which is :
J2EE API said:
Called by the servlet container to indicate to a servlet that the servlet is being placed into service.
So no, is not like a constructor, is like an initializer.

The documentation also says :
J2EE API said:
A convenience method which can be overridden so that there's no need to call [tt]super.init(config)[/tt].
So if that code still calls [tt]super.init()[/tt], then it means something important is implemented in the [tt]BaseServlet[/tt] class. Again, we not know what that class is.

Feherke.
 
thanks for your reply.

Yes BaseServlet extends HttpServlet

One question I have when you look at the public void init(), you see the declareation of three functions

protected RequestProcessor getRequestProcessor(Log log)
{
return new EDocsRequestProcessor(log);
}

protected WebController getWebController(EjbController ejbController, Log log)
{
return new EDocsWebController(ejbController, log);
}

protected EjbController getEjbController(Log log)
{
return new EDocsController(log);
}


Will it be true that any function that we declate in the
public void init(), will get executed on it its own because i see the declaration of these functions but not any code where we actually call these functions, as we do in other lauguages...

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top