Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GenericServlet.init()

 
Jimmy Chiu
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why GenericServlet.init(ServletConfig config)'s invocation on GenericServlet.init() can save my call to super.init(config) from my overriding init(ServletConfig config)?
In other words,
The Servlet Spec says that:
public void init()
throws ServletExceptionA convenience method 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().

Who can explain more on it?
Thanks,
-Jimmy
[ March 25, 2003: Message edited by: Jimmy Chiu ]
[ March 25, 2003: Message edited by: Jimmy Chiu ]
 
Ken Krebs
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jimmy,
The init() method in GenericServlet is provided simply for convenience. The init(ServletConfig) method in GenericServlet stores a reference to it's argument. The reference can later be obtained via the getServletConfig() method. If you override init(ServletConfig) in your own servlet, you should make sure to store the reference by calling super.init(ServletConfig) in your code. There is simply less chance for an error of omission by overriding init() instead of init(ServletConfig).
Ken, a.k.a. kktec
SCJP 1.4
working on SCWCD
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic