Struts 2 Basic Knowledge and struts2 basic knowledge
Struts 2 Overview
Struts framework 4 is widely used as an open-source MVC implementation. Struts 2 is a new-generation product of the Struts framework. It is a brand-new MVC framework compatible and integrated with Struts 1 and WebWork.
Struts 2 Framework Structure
The Framework Structure of Struts 2 differs greatly from that of Struts 1. Struts 2 is centered on WebWork and uses the interceptor mechanism to process users' requests. The interceptor mechanism of Struts 2 completely isolates the user's business logic controller from the Servlet API, and the business logic controller is more like a POJO (entity Layer ).
According to the Struts 2 Framework diagram, you can get a general idea of its processing process and steps:
1. The client initializes a request pointing to a Servlet container (such as Tomcat;
2. This request goes through a series of filters (these filters have an optional Filter called ActionContextCleanUp, which is very helpful for the integration of Struts2 and other frameworks, such as SiteMesh Plugin );
3. FilterDispatcher is called. FilterDispatcher asks ActionMapper to determine whether the request needs to call an Action;
4. If ActionMapper decides to call an Action, FilterDispatcher submits the request processing to ActionProxy;
5. ActionProxy queries the framework Configuration file through Configuration Manager and finds the Action class to be called;
6. ActionProxy creates an ActionInvocation instance.
7. The ActionInvocation instance uses the naming mode for calling. Before and after the Action is called, the call of the relevant Interceptor (Intercepter) is involved.
8. Once the Action is executed, ActionInvocation is responsible for finding the corresponding return result based on the configuration in struts. xml. The returned result is usually (but not always, or another Action chain) a template of JSP or FreeMarker to be represented. You can use the tag inherited from the Struts2 framework in the Process of representation. ActionMapper is required in this process.
Struts 2 Controller
Struts 2 Controller components are the core of the entire framework. In fact, all MVC frameworks are centered on controller components,
The core controller StrutsPrepareAndExecuteFilter is the core component of the Struts 2 framework. It is actually a servlet filter that acts on the entire web application and needs to be configured in web. xml, for example:
File address:
Any MVC framework needs to be integrated with web applications through the web. xml configuration file. Generally, the MVC framework only needs to load a core controller in a web application. For the Struts 2 framework, it is the core controller of the loader. A web application has the basic functions of Struts 2 after loading the core controller.
Because the core controller is a filter, you can use the <filter> and <filter-mapping> elements in the web. xml configuration file to configure the core controller. After the core controller is configured, the filter is loaded when the web application starts, and all requests in the running process must be filtered by the filter before further processing.
Action
Action is a user-defined business controller. The Code is as follows:
The Action class has an execute () method for business processing. In fact, the Business controller that plays a role in Struts 2 is not a user-defined Action, but an ActionProxy generated by the Struts 2 framework. However, the ActionProxy proxy is targeted at the user-defined Action. When configuring an Action, you must specify the implementation class of the Action and define the ing between the processing result of the Action and the view resource.
Configuration File
When the Struts 2 framework generates an ActionProxy proxy, you need to access the configuration file of Struts 2, which contains user-defined Action-related configuration information. The configuration files of Struts 2 are as follows:
1. Struts. xml configuration file, used to configure Action-related information;
2. Struts. properties attribute file, used to configure the global attributes of Struts 2.
Struts. xml configuration file code:
Create a Struts 2 project:
Http://www.cnblogs.com/fengxiongZz/p/6498216.html