Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts' ActionServlet.init()?

 
Pourang Emami
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Andy Bowes
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pourang Emami
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to frameworks forum.
 
Darryl A. J. Staflund
Ranch Hand
Posts: 312
2
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic