struts2 体系结构

来源:百度文库 编辑:神马文学网 时间:2024/05/11 11:43:18
struts2体系结构

In the diagram, an initial request goes to the Servlet container (such as Jetty or Resin) which is passed through a standard filter chain. The chain includes the (optional) ActionContextCleanUp filter, which is useful when integrating technologies such asSiteMesh Plugin. Next, the required FilterDispatcher is called, which in turn consults theActionMapper to determine if the request should invoke an action.
If the ActionMapper determines that an Action should be invoked, the FilterDispatcher delegates control to the ActionProxy. The ActionProxy consults the frameworkConfiguration Files manager (initialized from thestruts.xml file). Next, the ActionProxy creates an ActionInvocation, which is responsible for the command pattern implementation. This includes invoking any Interceptors (the before clause) in advance of invoking the Action itself.
Once the Action returns, the ActionInvocation is responsible for looking up the proper result associated with the Action result code mapped in struts.xml. The result is then executed, which often (but not always, as is the case forAction Chaining) involves a template written inJSP orFreeMarker to be rendered. While rendering, the templates can use theStruts Tags provided by the framework. Some of those components will work with the ActionMapper to render proper URLs for additional requests.
All objects in this architecture (Actions,Results,Interceptors, and so forth) are created by anObjectFactory. This ObjectFactory is pluggable. We can provide our own ObjectFactory for any reason that requires knowing when objects in the framework are created. A popular ObjectFactory implementation uses Spring as provided by theSpring Plugin.
Interceptors are executed again (in reverse order, calling the after clause). Finally, the response returns through the filters configured in the web.xml. If the ActionContextCleanUp filter is present, the FilterDispatcher will not clean up the ThreadLocal ActionContext. If the ActionContextCleanUp filter is not present, the FilterDispatcher will cleanup all ThreadLocals.