Personally, I wouldn't subclass the servlet or RequestProcessor for handling lifecycle events. If I needed access to Struts resources I would use a PlugIn, otherwise, one of the J2EE standard listener classes.
David
You perhaps know more about Struts than I do, but is there any place in say the
Struts docs or something which states what classes are to be used as-is and
which are meant to be extended? Or do you know or infer from your work that the
Struts creators never intended the ActionServlet to be extended? Because
frankly I don't see what would be wrong in writing differnet subclasses for
different applications - the core functionality of the ActionServlet would of
course still be where the majority of the brains of the framework resides. I
would envision very little "extra" work being done in the subclass proper; just
what is strictly needed for the particular application is all. Of course in the
original problem posed in this post, I suggested overriding the init() method.
The understanding of course was that super.init() would first be called. My
feeling is that as long as care such as this is taken, subclassing the
ActionServlet need not be something to shy away from..
Thank you for your response!
Geeta
John Espey wrote:
> I just get nervous any time I start extending a framework's classes and
> there are other ways to accomplish the same thing. Suppose you want to do
> other similar functionality on incoming requests. Then you extend the
> original base class. Then you need to build a different application after
> that, but don't need the functionality from the first subclass you made. Do
> you use the second subclass? If you use a listener, you just choose whether
> or not to deploy the listener in the next application you build. If you use
> a filter that puts a static member on the servlet context if it isn't
> already there, you can reuse that filter.
>
> I'm not saying don't extend classes that are meant to be extended (Action,
> ActionForm, etc.), I just think that given that the servlet spec gives you
> listeners and filters, your application server gives you startup classes,
> and Struts gives you the request processor and plugins, you have options
> that are more flexible than breaking the encapsulation of the ActionServlet
> by extending it.
>
> > -----Original Message-----
> > From: Geeta Ramani [mailto:[EMAIL PROTECTED]]
> > Sent: Thursday, February 20, 2003 2:47 PM
> > To: Struts Users Mailing List
> > Subject: Re: Universally Accessable Object
> >
> >
> > Hmm.. I don't know. I really don't see anything too "bad" about
> > extending the
> > ActionServlet.. Is there some reason you think this would create
> > problems? We
> > have used this method in one of our apps (which will go into production in
> > April) and haven't found any problems so far testing with it
> > 9almost six months
> > or so). But then we are really beginners in Struts so I'm sure
> > we could learn!
> > :)
> >
> > Geeta
> >
> > John Espey wrote:
> >
> > > Geeta,
> > > Do you really think this would be better than doing it in a
> > servlet context
> > > listener? If your container doesn't support that, wouldn't you
> > still prefer
> > > to write a plugin? Or a class that uses the class loader to
> > make sure the
> > > data only gets loaded once? Or a startup class (if you don't mind being
> > > tied to your container) I would think you'd want anything but
> > to extend the
> > > ActionServlet at this point.....
> > > John
> > >
> > > > -----Original Message-----
> > > > From: Geeta Ramani [mailto:[EMAIL PROTECTED]]
> > > > Sent: Thursday, February 20, 2003 2:22 PM
> > > > To: Struts Users Mailing List
> > > > Subject: Re: Universally Accessable Object
> > > >
> > > >
> > > > Larry:
> > > >
> > > > An easy way to do this would be to:
> > > >
> > > > 1. Write a controller class which extends the Struts ActionServlet.
> > > > 2. Declare a *static* object of type (say) Hashtable in this
> > controller.
> > > > 3. In the init() method of the controller, write code to
> > > > initialise this hashtable.
> > > > 4. Finally make the appropriate markings in your web.xml so that
> > > > your controller (rather than the Struts' ActionServlet) is what
> > > > is called with a url-pattern of *.do and make sure the controller
> > > > has a load-on-startup param as 1.
> > > > 5. In your Action classes, you can then access this object in the
> > > > normal way: MyController.myHashtable.
> > > >
> > > > Hth!
> > > > Regards,
> > > > Geeta
> > > >
> > > > Larry Hytail wrote:
> > > >
> > > > > I have a table of information contained in a backend database.
> > > > The table is not very big and never will be. I would like to
> > > > create an object that holds the values from this table. I would
> > > > like this object to instantiate when the struts webapp is
> > > > started. Then I would like to be able to access this object from
> > > > any Action object within my struts application. Questions:
> > > > >
> > > > > 1) Where is the best place to put the instantiation of this object?
> > > > >
> > > > > 2) How do I get a handle on the object from the Action object?
> > > > >
> > > > > Larry Hytail
> > > > >
> > > > > ---------------------------------
> > > > > Do you Yahoo!?
> > > > > Yahoo! Tax Center - forms, calculators, tips, and more
> > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]