RoseIndia struts2 翻译 - Struts 2 Architecture

Struts 2 Architecture

Struts 2 架构

Struts and webwork has joined together to develop the Struts 2 Framework. Struts 2 Framework is very extensible and elegant for the development of enterprise web application of any size. In this section we are going to explain you the architecture of Struts 2 Framework

struts 和 webwork 一起组成了struts2开发框架。struts 2 框架具有很高的扩展性适合开发任何大小的企业级应用程序。在这一章我们会为您解释struts2框架的架构。


    1. Request Lifecycle in Struts 2 applications

Struts 2应用程序的请求生命周期

  1. FilterDispatcher determines the appropriate action: The FilterDispatcher looks at the request and then determines the appropriate Action.
    FilterDispatcher 将决定哪个action将会被调用: FilterDispatcher 会根据请求来决定哪一个action被调用
  2. Interceptors are applied: Interceptors configured for applying the common functionalities such as workflow, validation, file upload etc. are automatically applied to the request.
    Interceptors 被应用在框架中: 配置拦截器是为了在接受请求时自动调用公共的一些功能 比如工作流, 验证,文件上传等等这些 
  3. 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中的方法会被执行以便于执行一些数据库相关操作 比如排序, 数据检索。
  4. Output rendering: Then the Result renders the output.
    输出转向:然后结果会被转到输出。
  5. 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的返回:然后结果会以拦截器拦截请求相反的顺序被返回。返回请求可以使我们来执行一些清理或者附加的操作。
  6. 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 request processing:

图片:struts 2 request 执行过程一览


 
Struts 2 Architecture

 struts 2 架构


Struts 2 is a very elegant and flexible front controller framework 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 data access technologies like JDBC, EJB, Hibernate etc and for the View, the framework 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 exception handlers 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 of Struts 2 Framework and also shows the the initial request goes to the servlet container such as tomcat, which is then passed through standard filer chain.

下面的图表描述了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,反而会清理。

(本章完).

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。
04-26
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值