Hi,
Can anyone tell me the scenario in which I should extend ActionServlet class and RequestProcessor? I have read in the Struts documentation that it can be done, but I am not understanding in which situtaion.
Regards,
Aashutosh
Hi,
Can anyone tell me the scenario in which I should extend ActionServlet class and RequestProcessor? I have read in the Struts documentation that it can be done, but I am not understanding in which situtaion.
Regards,
Aashutosh
The ActionServlet and RequestDispatcher are main players in the Struts framework. ActionServlet treats all requests made to your Struts application and delegates the "heavy lifting stuff" of handling the request to a RequestProcessor object.
In a Struts application you usually have your operations performed by creating Action classes, each Action taking care of its own different stuff. Sometimes though you wish to perform common operations for all Actions like logging or security and you don't want them performed inside each Action class do you? That will mean a lot of code duplication, so you have to place this common behavior somewhere above the individual Actions.
The ActionServlet and RequestProcessors make good candidates for this sort of stuff. Sure, you could write a filter but the ActionServlet and RequestProcessors already contain code related to your framework so there is not point in starting from scratch with something when you can reuse what already exists and extend it.
The subject of extension is typically the RequestProcessor (more than the ActionServlet) so read the JavaDoc of the RequestProcessor and you will see there are a lot of useful methods to extend and add hooks to important stages of the execution.
To give you a concrete example: the Tiles Plugin makes use of an extension of the RequestProcessor.