The Struts2 Servlet Filter

When requests are received at the servlet container, they are forwarded to either a servlet or a filter that will handle processing the request. In Struts2, a filter is used, and the class for handling the request is the FilterDispatcher class. 

The filter and a Dispatcher class (to which many of the tasks are delegated) are the heart of the Struts2 framework. Together, they provide access to the infrastructure that will be needed to process the request. Upon startup, implementations of configurable elements in the framework, including ConfigurationManager, ActionMapper, and ObjectFactory, are loaded. With respect to processing the request, the Struts2 filter performs the following:

Serves static content: Dojo content, JavaScript, and user configurable files can be served from the Struts2 or the web application’s JAR file, allowing all the elements for a web application to be packaged together.

Determines the action configuration: The filter uses the ConfigurationManager and the ActionMapper implementations to determine which action maps to the URL from the incoming request; by default, actions are determined by looking for a .action extension.

Creates the action context: Because actions are generic and not specific to HTTP ,  the information contained in the web request needs to be converted to a protocol-independent format for the actions to use; this includes extracting data from the HttpServletRequest and the HttpSession objects.

Creates the action proxy: There is an additional layer of indirection in the processing in the form of an ActionProxy class. This class contains all the configuration and context information to process the request and will contain the execution results after the request has been processed.

Performs cleanup: To ensure that no memory leaks occur, the filter automatically performs cleanup of the ActionContext object.

When the ActionProxy class instance is created and configured, the execute() method is invoked. This signals that the preparation of the action is complete, and the real processing of the action is about to start.

 

posted @ 2013-04-26 10:45  MagicLetters  阅读(128)  评论(0编辑  收藏  举报