开发者

Extending Struts ActionServlet and RequestProcessor

开发者 https://www.devze.com 2023-01-19 06:39 出处:网络
Can anyone tell me the scenario in which I should extend the ActionServlet and RequestProcessor classes? I have read in the Struts documentation that it can be done, but I don\'t under开发者_高级运维s

Can anyone tell me the scenario in which I should extend the ActionServlet and RequestProcessor classes? I have read in the Struts documentation that it can be done, but I don't under开发者_高级运维stand in which situation.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消