aspose file tools*
The moose likes Struts and the fly likes Struts' ActionServlet.init()? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts Watch "Struts New topic
Author

Struts' ActionServlet.init()?

Pourang Emami
Ranch Hand

Joined: Sep 21, 2002
Posts: 127
Hi
I have some activities to take place just at the
beginning of my application.
How can I get access to ActionServlet to put them inside it's init() method?
(I looked for this file every where in my root directory inside jdeveloper/mywork/wrkspc/prj/..
but I couldn't find it.)
Is there any other way to do it?
Thank you for your time.
Best Regards,
Pourang Emami


Best Regards,<br />Pourang Emami
Andy Bowes
Ranch Hand

Joined: Jan 14, 2003
Posts: 171
The source code for Struts can be downloaded from the Apache.org site.
Another solution that would not involve the modification of the Struts ActionServlet would be to create your own servlet that is loaded on application startup and to put your code in it's init() method. In my opinion this would be preferable to modifying the Struts servlet as it would mean that you would not have to re-apply the modification if you decided to move to another version of Struts.


Andy Bowes<br />SCJP, SCWCD<br />I like deadlines, I love the whoosing noise they make as they go flying past - Douglas Adams
Pourang Emami
Ranch Hand

Joined: Sep 21, 2002
Posts: 127
Dear Andy
Actually this is exactly the kind of job I've done.I have created a class extending ActionServlet and put the codes inside it's init().
But according a friend, this is the ActionServlet is called at the start-up and so by having another class clled in the start-up I will get the control out of the ActionServlet?
Any idea?
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Moving to frameworks forum.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Darryl A. J. Staflund
Ranch Hand

Joined: Oct 06, 2002
Posts: 303
Hi there,
If you want to do a one-time run some code during startup of a Struts application, the recommended way to do it (in Struts 1.1) is to develop a plugin. You do this as follows:
1. Create a class that implements the org.apache.struts.action.PlugIn interface.
2. Create an init () method in the new class that contains your startup code. See the PlugIn API for the specifics on what needs to be done here.
3. Register the plug-in at the bottom of the struts-config.xml file. See the struts-config.xml DTD on how to do this.
And that should be it.
If, on the other handle, you want to modify and extend the behaviour of Struts' RequestProcessor (for example, if you want to modify Struts' handling of action-based security), then you should do the following:
1. Create a class that implements org.apache.struts.action.RequestProcessor.
2. Override the appropriate method whose behaviour you want to modify. For instance, if you want to modify Struts' handling of action-based security, override the 'processRoles' method. See the RequestProcessor API for a complete list of methods.
3. Register your RequestProcessor in the struts-config.xml file using the '<controller />' tag. See the struts-config.xml DTD for more information on how to do this.
BTW, the Struts Tiles plugin implements its own RequestProcessor, so if you want to use your RequestProcessor alongside the Tiles' RequestProcessor, make sure your processor extends TilesRequestProcessor instead of implementing RequestProcessor. If you don't Tiles will crap out during start-up.
Cheers,
Darryl
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts' ActionServlet.init()?