`

Apache Struts2 Architecture

阅读更多

Struts is a flexible control layer based on standard technologies like Java Filters, JavaBeans, ResourceBundles, Locales, and XML, as well as various OpenSymphony packages, like OGNL and XWork.

For the Model, the framework can interact with standard data access technologies, like JDBC and EJB , as well as most any third-party packages, like Cayenne , Hibernate , or iBATIS .

For the View, the framework works well with JavaServer Pages , including JSTL and JSF, as well as FreeMarker or Velocity Templates, PDF, XSLT, and other presentation systems.

Aside from actions and results, we can specify exception handlers and interceptors .

  • Exception handlers declare how to handle an exception on a global or local basis. Instead of sprinking source code with try .. catch blocks, we can let the framework catch the exception and display the page of our choice. The page can display an appropriate message and details from the exception.
  • Interceptors specify the "request-processing lifecycle" for an action. (What happens to the request before and after the Action class fires.) We can specify both global and local lifecycles. If some actions respond to AJAX, SOAP, or JSF requests, we can simplify the lifecycle, and even just "pass through" the request, if needed. However, these are special cases, and most applications can use the default interceptor stack, "out of the box".

The diagram describes the framework's architecture.

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 as SiteMesh Plugin . Next, the required FilterDispatcher is called, which in turn consults the ActionMapper 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 framework Configuration Files manager (initialized from the struts.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 for Action Chaining ) involves a template written in JSP or FreeMarker to be rendered. While rendering, the templates can use the Struts 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 an ObjectFactory . 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 the Spring 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.

分享到:
评论

相关推荐

    struts2_core_JAR开发包

    8. **Plug-in Architecture(插件架构)**:Struts2的插件机制允许开发者扩展其功能,如Struts2-dojo-plugin提供了与Dojo库的集成,Struts2-json-plugin支持JSON响应等。 在"struts2_core_JAR开发包"中,包含了...

    struts-2.3.24所有架包

    5. **插件架构(Plugin Architecture)**:Struts2支持插件扩展,可以方便地添加新的功能或集成其他框架。 6. **强大的表单和验证机制**:Struts2提供了一套完整的表单处理和验证机制,通过注解或者XML配置即可实现...

    struts2所有jar包下载

    3. **Dependency Libraries**:Struts2依赖于其他开源库,如Apache Commons Lang、Ognl(Object-Graph Navigation Language)、Freemarker模板引擎等,这些库的JAR文件也需要一并下载。 4. **Struts2的文档**:通常...

    struts2+ibatis

    Struts2是Apache软件基金会的开源项目,它是Struts1的升级版,提供更强大的功能和更好的性能。Struts2的核心是Action类,它接收HTTP请求并调用业务逻辑,然后将结果传递给视图进行展示。Struts2通过Interceptor...

    struts2_lib.zip

    6. **Plug-in Architecture**:Struts2支持插件架构,允许开发者扩展框架功能,比如添加新的拦截器、结果类型等。 7. **Freemarker and JSP**:Struts2支持使用Freemarker和JSP作为视图技术,Freemarker提供了更...

    xfire+struts2的资源包

    标题中的“xfire+struts2的资源包”指的是一个包含xfire和Struts2框架相关组件的集合,这些组件通常用于构建Java Web应用程序。Xfire是一个基于Java的SOAP服务框架,而Struts2是一个流行的MVC(模型-视图-控制器)...

    struts2_3000_BBS2009_02.rar

    Struts2是一个非常著名的Java Web开发框架,由Apache软件基金会维护。这个压缩包"struts2_3000_BBS2009_02.rar"可能包含了Struts2框架的一个实例,可能是BBS(论坛)应用的源代码,版本号可能是2009年的第二个迭代。...

    struts2.1 完整版下载

    3. **插件架构(Plugin Architecture)**:Struts2支持丰富的插件,如Freemarker和JSP视图技术,以及各种国际化和主题的支持。这使得开发者可以根据需求选择不同的技术栈,增强应用的功能。 4. **动态方法调用...

    struts2.3.4文档(最新版本)

    4. **插件架构(Plugin Architecture)**:Struts2允许扩展其核心功能,通过插件实现。例如,开发者可以使用Tiles插件来管理页面布局,或者使用Freemarker或Velocity作为视图技术。 5. **模型-视图-控制器(MVC)**...

    Struts2.3.1.1chm格式帮助文档

    10. **Plugin Architecture**:Struts2的插件架构使得扩展和集成其他技术变得简单,如Spring、Hibernate等。 Struts2.3.1.1 版本可能包含以下更新和改进: - 性能优化:提高框架处理请求的速度。 - 安全修复:修复...

    xworkdocs 对struts2学习有帮助

    它最初是为Apache Struts2项目开发的核心组件之一,但后来发展成为一个独立的框架。XWork的核心功能包括:处理用户请求、执行业务逻辑、数据转换以及验证等。它通过定义一套简洁而强大的API来实现这些功能,使得...

    struts-core-1.3.10.jar.zip

    Struts是Apache软件基金会(ASF)旗下的一个开源项目,它是一个用于构建企业级Java Web应用程序的MVC(Model-View-Controller)框架。Struts 1.3.10是Struts 1系列的一个版本,提供了对Web应用的结构化支持,帮助...

    compass+ssh2集成 hibernategps问题

    标题中的"compass+ssh2集成 hibernategps问题"涉及到三个主要的技术概念:Compass、SSH2(可能是指的是Apache Struts 2或者Secure Shell 2)以及Hibernate GPS。接下来我们将详细探讨这些技术及其可能的问题。 1. *...

    Struts与Web应用的联合编程入门

    Struts框架是Apache基金会Jakarta项目组中的一个开源项目,它是一个基于MVC架构的Web开发框架。在Struts框架中,Servlet作为控制器,JSP作为视图,JavaBean作为模型。 **图1-6 Struts MVC架构** ![Struts MVC架构]...

    基于Hibernate和Struts的J2EE应用开发

    Struts框架遵循MVC(Model-View-Controller)设计模式,它是Apache Jakarta项目的一部分,专门为J2EE环境设计。MVC模式将应用程序分为三个核心组件: 1. **模型(Model)**:负责管理应用程序的数据逻辑,通常与...

    ssh lib包2

    7. **struts2-dojo-plugin-2.1.8.1.jar**:Struts 2是基于MVC架构的Web应用框架,而Dojo插件则扩展了Struts 2的功能,引入了Dojo JavaScript库,用于创建交互式的Web用户界面。 8. **xwork-core-2.1.6.jar**:XWork...

    SOA\精通SOA_基于服务总线的Struts+EJB+Web Service整合应用开发

    Struts是Apache软件基金会的一个开源项目,它是MVC(Model-View-Controller)设计模式的一个实现,主要用于Java Web应用程序的开发。Struts提供了控制器组件,帮助开发者将业务逻辑与表现层分离,提高了代码的可维护...

    struts2.0.11.rar_Java编程_Java_

    2. **插件架构(Plugin Architecture)**:Struts2支持多种插件,如Freemarker和Velocity视图技术、JSON和XML数据格式化、Tiles布局框架等,使得开发者能够灵活选择合适的技术栈。 3. **OGNL(Object-Graph ...

Global site tag (gtag.js) - Google Analytics