RoseIndia struts2 翻译 - Struts 2 ArchitectureStruts 2 ArchitectureStruts 2 架构Struts and webwork
RoseIndia struts2 翻译 - Struts 2 Architecture
Struts 2 Architecture
Struts 2 架构
Struts and webwork has joined together to develop theStruts 2 Framework. Struts 2 Framework is very extensible and elegant for the developmentof enterprise web application of any size. In this section we are going toexplain you the architecture of Struts 2 Framework
struts 和 webwork 一起组成了struts2开发框架。struts 2 框架具有很高的扩展性适合开发任何大小的企业级应用程序。在这一章我们会为您解释struts2框架的架构。
?? ?1. Request Lifecycle in Struts 2 applications
Struts 2应用程序的请求生命周期
FilterDispatcher determines the appropriate action:?The FilterDispatcher looks at the request and then determines the appropriate Action.FilterDispatcher 将决定哪个action将会被调用:?FilterDispatcher 会根据请求来决定哪一个action被调用Interceptors are applied: Interceptors configured for applying the common functionalities such as workflow, validation, file upload etc. are automatically applied to the request.
Interceptors 被应用在框架中: 配置拦截器是为了在接受请求时自动调用公共的一些功能 比如工作流, 验证,文件上传等等这些?
Execution of Action: Then the action method is executed to perform the database related operations like storing or retrieving data from the database.
Action 的执行:拦截器拦截了请求之后,action中的方法会被执行以便于执行一些数据库相关操作 比如排序, 数据检索。Output rendering: Then the Result renders the output.
输出转向:然后结果会被转到输出。Return of Request: Then the request returns through the interceptors in the reverse order. The returning request allows us to perform the clean-up or additional processing.
Request的返回:然后结果会以拦截器拦截请求相反的顺序被返回。返回请求可以使我们来执行一些清理或者附加的操作。Display the result to user: Finally the control is returned to the servlet container, which sends the output to the user browser.
??给用户显示结果:最后控制权会交给servlet容器, 容器会把结果返回给用户浏览器
Image: Struts 2 high level overview of requestprocessing:
图片:struts 2 request 执行过程一览

?Struts 2 Architecture
?struts 2 架构
Struts 2 is a very elegant and flexible front controllerframework based on many standard technologies like Java Filters, Java Beans,ResourceBundles, XML etc.?
struts 2 是非常优雅和灵活的前端控制器类型的框架,此框架是基于很多标准技术比如java 过滤器, java beans,?ResourceBundles 和xml 等等。
For the Model, the framework can use any dataaccess technologies like JDBC, EJB, Hibernate etc and for the View, theframework can be integrated with JSP, JTL, JSF, Jakarta Velocity Engine,Templates, PDF, XSLT etc.
在模型端, struts 2 框架可以利用任何数据访问技术比如说jdbc , EJB, Hibernate 等等。 在视图端,struts2 可以结合JSP, JTL, JSF,?akarta Velocity Engine, Templates, PDF, XSLT 等等。
Exception Handling:
异常处理
The Struts 2 Framework allows us to define exceptionhandlers and inceptors.
strtus 2 框架允许我们定义异常处理和拦截器
Exception Handlers:?异常处理:
Exception handlers allows us to define the exception handling procedure on global and local basis. Framework catches the exception and then displays the page of our choice with appropriate message and exception details.??异常处理可以让我们定义自己的异常处理过程, 过程可以是全局的也可以是局部的。 框架会捕捉异常, 然后我们可以选择恰当的信息和异常具体的内容来通过??网页的形式显示给用户
Interceptors:??拦截器:
The Interceptors are used to specify the "request-processing lifecycle" for an action. Interceptors are configured to apply the common functionalities like workflow, validation etc.. to the request.?拦截器是为了定义给action特定的 “请求-处理生命周期“给 action. 拦截器是配置给请求一些公共的功能比如工作流, 验证等等。
The following diagram depicts the architecture ofStruts 2 Framework and also shows the the initial request goes to theservlet container such as tomcat, which is then passed through standard filerchain.
下面的图表描述了Struts 2框架的架构,也显示了初始请求时如何在tomcat这样的容器中被处理的,处理过程是通过一些标准的过滤链。
Image: Struts 2 Architecture
图片:struts 2 架构

?
?
The filter chain includes:
过滤链包括了:
Action ContextCleanUp filter:
The ActionContextCleanUp filter is optional and it is useful when integration has to be done with other technologies like SiteMash Plugin.?? ? ? ActionContextCleanUp filter 是可选的, 它特别适用于党其它的技术和struts 2框架结合的时候, 比如说 ? ? ? ? ? ? ? ? ? ?SiteMash 插件。
FilterDispatcher:? Next the FilterDispatch is called, which in turn uses the ActionMapper to determine whether to invoke an Action or not. If the action is required to be invoked, the FilterDispatcher delegates the control to the
ActionProxy.??? ? ?然后FilterDispatch 会被调用, 它会使用ActionMapper 来决定是否调用Action. 如果Action是必须被调用的, ? ? ? ? ? ? ? FilterDispatcher 会把控制交给ActionProxy(Action 代理)
ActionProxy:(Action 代理)
The ActionProxy takes help from Configuration Files manager, which is initialized from the struts.xml. Then the ActionProxy creates an
ActionInvocation, which implements the command pattern. The ActionInvocation process invokes the Interceptors (if configured) and then invokes the action. The the ActionInvocation looks for proper result. Then the result is executed, which involves the rendering of JSP or templates.??? ? ? ? ?Action 代理会得到 Configuration Files Manager 的相助, 然而Configuration Files Manager是根据struts.xml被初始化的。 然后Action 代理会创建 ? ? ? ? ? ?一个ActionInvocation, 它执行了公共模式。?ActionInvocation 处理过程调用了拦截器(如果拦截器被配置上了)然后调用action. 接着 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?ActionInvocation会寻找合适的结果。 最后结果被执行, 执行过程包括转发到JSP或者模板
Then the Interceptors are executed again in reverse order. Finally the response returns through the filters configured in web.xml file. If the ActionContextCleanUp filter is configured, the FilterDispatcher does not clean the ThreadLocal ActionContext. If the ActionContextCleanUp filter is not present then the FilterDispatcher will cleanup all the ThreadLocals present.?然后一系列拦截器按照相反的顺序再次执行。最后response被在web.xml文件里配置好的过滤器返回。如果配置了ActionContextCleanUp, 那么?FilterDispatcher 不会清理?ThreadLocal ActionContext,反而会清理。
(本章完).
?
?