登录 | 注册











2、什么是struts2 framework?

struts2 framework是基于webwork framework;

struts2 是实现MVC设计模式的第二代应用框架;





The role of the controller is played by the Struts 2 FilterDispatcher。

model is implemented by the Struts 2 action component。










In more technical terms, the model is the internal state of the application. --在更多的技术方面,模型是应用程序的内部状态。

This state is composed of both the data model and the business logic. --这种状态由数据模型和业务逻辑组成。

business logic and data from the database will be involved in the authentication process. --业务逻辑和数据库中存放的数据都会参与到身份验证过程。

Neither the data on its own, nor the business logic on its own, can produce these states. --仅有数据或者仅有业务逻辑都不能生成生成这种状态。


First, an action is an encapsulation of the calls to business logic into a single unit of work. --第一,一个动作调用业务逻辑进入一个单独的工作单元。

Second, the action serves as a locus of data transfer. --第二,动作是一个数据传输的场所。


how do you get all the richness you desire without actually “combining” the ingredients? --如何获得你想要的丰富功能,而不把所有的因素搅在一起呢?

it translates the state of the application into a visual presentation with which the user can interact.


it becomes even more important to have clean MVC separation of concerns.


One of the interesting aspects of Struts 2 is how well its clean architecture paves the way for new technologies and techniques.


This makes it easy for alternative responses, such as XML snippets or XSLT transformations, to be integrated into the framework.


Common choices are between results that represent the semantic outcomes of the action’s processing, such as “success” and “error.”


Struts 2 provides out-of-the-box support for using most common view-layer technologies as results.

(为了使用大多通用的视图框架技术展现结果,Struts2 提供了原生的支持)

Better yet, the clean structure of the architecture ensures that more result types can be built to handle new types of responses.


Since this favored MVC pattern has been around for decades, try visualizing what the MVC playing field would look like if the players were in fact nicely separated yet connectible.


Grab some sweets and continue reading to learn about Struts 2 and the framework request-processing factory.


How Struts 2 works


These clean lines are only possible with the help of a few other key architectural components that participate in processing every request.


We’ll explain in the next paragraphs how the interceptors and the ActionContext aid the action and result in their processing of the request.



We’ll devote an entire chapter to this important component later in the book.


At this time, it is enough to understand that most every action will have a stack of interceptors associated with it.


These interceptors are invoked both before and after the action, though we should note that they actually fire after the result has executed.


Interceptors don’t necessarily have to do something both times they fire, but they do have the opportunity.


Some interceptors only do work before the action has been executed, and others only do work afterward.


The important thing is that the interceptor allows common, cross-cutting tasks to be defined in clean, reusable components that you can keep separate from your action code.


They provide an architectural component in which to define various workflow and cross-cutting tasks so that they can be easily reused as well as separated from other architectural concerns.


Logging should be done with the invocation of every action, but it probably shouldn’t be put in the action itself.


Because it’s not part of the action’s own unit of work.


It’s more administrative, overhead if you will.


Earlier, we charged a framework with the responsibility of providing built-in functional solutions to common domain tasks such as data validation, type conversion, and file uploads.


While these tasks are important, they’re not specifically related to the action logic of the request.


Interceptors play a huge role in the Struts 2 framework.



While interceptors may not absorb a lot of your daily development energies, the ValueStack and OGNL will be constantly on your mind.

(虽然拦截器不能消耗你太多的日常开发精力, 但是你必须时刻牢记ValueStack和OGNL)

In a nutshell, the ValueStack is a storage area that holds all of the data associated with the processing of a request.


You could think of it as a piece of scratch paper where the framework does its work while solving the problems of request processing.


Rather than passing the data around, Struts 2 keeps it in a convenient, central location—the ValueStack.

(Struts2将数据集中保存在一个方便的位置,而不是传来传去 -- 这个地方就是ValueStack)

OGNL is the tool that allows us to access the data we put in that central repository.


More specifically, it is an expression language that allows you to reference and manipulate the data on the ValueStack.


Developers new to Struts 2 probably ask more questions about the ValueStack and OGNL than anything else.


If you’re coming from Struts 1, you’ll find that these are a couple of the more exotic features of the new framework.


The ActionContext contains all of the data that makes up the context in which an action occurs.


This includes the ValueStack but also includes stuff the framework itself will use internally, such as the request, session, and application maps from the Servlet API.

(ActionContext包含ValueStack,当同时也包含使用在内部的框架本身,例如:请求、session、来自Servlet API的应用图)

The framework provides many elegant ways to interact with that data without actually touching the ActionContext, or the ValueStack, yourself.



These tasks are sometimes referred to as cross-cutting concerns because they occur again and again across the execution of a disparate set of application-specific actions.


In Struts 2, the interceptor provides an architectural mechanism for removing cross-cutting concerns from the core MVC components.


2020 jeepxie.net webmaster#jeepxie.net
10 q. 0.009 s.