tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tom Woteki <d...@woteki.com>
Subject Re: Using a servlet superclass
Date Mon, 12 Feb 2001 02:13:34 GMT
Perhaps this will work, though I am not so certain of the life cycle of a
servlet to say for sure:

Define the default (i.e. no argument) constructor for SuperServlet (its
signature is: SuperServlet() ) within which you call init. Any child of
SuperServlet should then automagically call init (or any override of it)
when its own default constructor is invoked: default constructors are
automatically invoked to the top of the inheritance hierarchy.

Dr. Wo
-- 
Tom Woteki, a.k.a. Dr. Wo
mail to:<drwo@woteki.com>
202-544-2743 (fax)
http://www.woteki.com/wines <-- a pure Java, Apache-Tomcat web application
running under MacOSX

> From: Jill Stephenson <jill.s@jabcreative.com>
> Reply-To: tomcat-user@jakarta.apache.org
> Date: Sun, 11 Feb 2001 20:52:03 -0500
> To: "'tomcat-user@jakarta.apache.org'" <tomcat-user@jakarta.apache.org>
> Subject: Using a servlet superclass
> 
> I have a number of servlets in my application that need to
> perform common initialisation, etc.  So I was thinking of
> creating a superclass that has an init method that does all
> of the common work, eg.,
> 
> public class SuperServlet extends HttpServlet {
> public void init() {
>   // do common initialisation stuff in here
> } // init
> } // SuperServlet
> 
> Then all the workers servlets would extend SuperServlet
> rather than HttpServlet, eg.,
> 
> public class WorkerServlet extends SuperServlet {
> ...
> } // WorkerServlet
> 
> This seems to be OK, until I implement init in the
> WorkerServlet, as the init method in the SuperServlet
> does not then get invoked.  While I can call super.init()
> in the WorkServlet, I want this to be handled automatically
> as I can bet on someone forgetting this step, eg.,
> 
> public class WorkerServlet extends SuperServlet {
> public void init() {
>   // don't want to have to make this call ==> super.init();
> } // init 
> ...
> } // WorkerServlet
> 
> Is there any way to implement this ?
> 
> ----
> Jill
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, email: tomcat-user-help@jakarta.apache.org
> 


Mime
View raw message