Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why super.init() is used??

 
jacob deiter
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



1)why "super.init(config)" is used in servlet ???.
2) what is the use of this?
3) in every servlet ,this should be used??

 
Yeray Santana Borges
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi jacob,

First, the container call the default constructor of your servlet class, and after that call the init(ServletConfig config), this method is in GenericServlet class. Normally you extends the HttpServlet, and HttpServlet extends from GenericServlet class.

If you override the init(ServletConfig config) in your class that extends HttpServlet you must call super.init(Servetconfig config), without this call to super, the code inside of your parent class (GenericServlet) don’t run and you can have problems. I don’t know what happens exactly in the GenericServlet init(ServletConfig), but in the init(ServletConfig) in GenericServlet class the servlet do a initialized job whit ServletConfig and ServletContext objects.

Whit the ServletConfig object, the container can pass information to the servlet class, for example the init parameters in the deployment descriptor, and a reference to ServletContext. Whit the ServletContext object the servlet can communicate with the container and, for example, can have access to log files.

It is better override the init() (without arguments) method in your servlet class. The init(ServletConfig config) in GenericServlet call the init() method when finish.
If you need a reference to ServletConfig object in your init() overridden method, you can use getServletConfig() to get a reference to it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic