A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service
The Struts 2 framework itself can be roughly divided into 3 parts: Core controller Filterdispatcher, Business Director Action and user implementation of enterprise business logic components.
The core controller Filterdispatcher is the foundation of the Struts 2 framework. Includes the control flow and processing mechanism inside the framework. Business controller action and business logic components are required to be implemented by the user. At the same time that users develop action and business logic components, they also need to write the relevant configuration files for use by the core controller filterdispatcher. The work flow of struts 2 is simpler than struts 1, which is basically the same as the webwork framework, so struts 2 is the upgrade version number of WebWork.
Basic brief processes such as the following:1. The client browser makes an HTTP request. 2, according to the Web. XML configuration, the request was Filterdispatcher received.
3, according to Struts.xml configuration. Find the Action class and method that need to be called, and pass the IOC mode. Injects a value to Aciton.
4. Action invokes the business logic component to process the business logic, which includes form validation. 5, the action is completed, according to the configuration in the Struts.xml find the corresponding result of the return, and jump to the corresponding page. 6. Returns the HTTP response to the client browser.2. Core controller: Filterdispatcher
The Filterdispatcher is the core controller of the Struts 2 framework. The controller is executed as a filter in the Web application, and it is responsible for intercepting all user requests. When a user request arrives, the filter filters the user request.
Assuming that the user request ends with an action, the request is transferred to the Struts 2 framework for processing.
After the Struts 2 framework obtains the *.action request, it will decide which business logic component to invoke, for example, based on the previous part of the *.action request. For login.action requests. Struts 2 calls the action named Login to process the request.
The action in the Struts 2 app is defined in the Struts.xml file. When you define an action in the file, the Name property and the class property of the action are defined. The Name property determines which user request the action handles, and the class property determines the implementation class for the action.
The action instance that Struts 2 uses to process user requests is not a user-implemented business controller. Instead, the action agent-because the user implements a business controller that is not coupled to the Servlet API, it is clear that user requests cannot be processed.
The Struts 2 framework provides a series of interceptors, which are responsible for parsing the request parameters in the HttpServletRequest request, passing in the action, and callback the action's Execute method to handle the user request.
Obviously. The above process is a typical AOP (aspect-oriented programming) approach.
The user-implemented action class is not the proxy target of the action agent for Struts 2.
The user-implemented business controller (Action) includes the processing of user requests. The user's request data is included in the HttpServletRequest object, and the user's action class does not need to be interviewed for the HttpServletRequest object.
The interceptor is responsible for parsing the request data in the HttpServletRequest. and passed to the business logic component action instance.3. Business Controller
A business controller component is an instance of a user implementing an action class. The action class typically includes an Execute method that returns a string-the string is a logical view name. When the business controller finishes processing the user request, the results are different depending on the processing. The Execute method returns a different string-the corresponding view name for each string.
Once the program ape has developed the business controller needed for the system, it will need to configure the action of Struts 2. That is, you need to configure the action for example the following three-part definition:
The URL that the-action handles.
The corresponding implementation class for the-action component.
The corresponding relationship between logical views and physical resources included in the-action.
Each action has to process a user request. The user request always includes the specified URL. When filter dispatcher intercepts a user request, it processes the forwarding according to the corresponding relationship between the URL and the action that the request is handling.Model Components for 4.Struts 2
In fact, the model components are beyond the scope of the MVC framework.
For the STRUTS2 framework, there is usually not much help for the implementation of the model component.
Usually refers to the business logic component of the system. The following are hidden in the system's business logic components, which may also include DAO, domain objects, and so on.
Typically, the business controller in the MVC framework invokes the method of the model component to handle the user request.
Other words. The business logic controller does not perform any actual processing of user requests. The user request is finally handled by the model component. The business controller is only the scheduler that is responsible for dispatching in the middle. This is also why the action is called the controller.
When the controller needs to obtain a business logic component instance. Typically, the business logic component instances are not directly obtained. Instead, an instance of the business logic component is obtained through Factory mode. Or use other IOC containers, such as the spring container, to manage instances of business logic components.View components for 5.Struts 2
Struts 2 has changed struts 1 to use JSP as a view technology only, Struts 2 agrees to use other templating techniques, such as freemarker, velocity as the view technology.
When the controller of Struts 2 returns the logical view name. The logical view is not associated with any view technology, but returns a string. The string as the logical view name.
When we configure the action in the Struts.xml file. Not only do you specify the name and class properties of the action, but you also specify the series result child element for the action element, and each result child element defines a mapping between a logical view and a physical view. The applications described earlier use JSP technology as a view. Therefore, the type attribute is not specified when the result child element is configured. The JSP is used as the view resource by default.
Assuming that you need to use other view techniques in Struts 2, you can specify the corresponding type property when you configure the result child element.
For example, if you need to use Freemarker, specify the type attribute with value Freemarker for result, and suppose you want to use velocity template technology as a view resource. Then for result, specify a value of the Type property of velocity ...Implementation process for 6.Struts 2
Through the above introduction. We found that the STRUTS2 framework's execution process was similar to the WebWork framework's process.
Tip on the official website of Struts 2, we are able to find examples such as the following: Essentially,struts 2.0 is the technical equivalent of WebWork 2.3. Aside fromthe package and property renaming. It isn ' t much different than,say,migratingfrom WebWork 2.1 to 2.2--means that Struts 2.0 technology is equivalent to the WebWork 2.3 framework, except for packages and attributes that are renamed outside. Migrating from WebWork 2.2 to struts 2 is no more complex than migrating from WebWork 2.1 to WebWork 2.2.
Here we can see that Struts 2 is in fact the WebWork 2.2 upgrade version. This is not difficult to understand: why WebWork and Struts 2 are so similar!
Struts struts is just an MVC framework (framework) for high-speed development of javaweb applications. The focus of struts implementation is in C (Controller). Includes Actionservlet/requestprocessor and our custom action, as well as a series of custom labels (customtag) for V (View). But struts almost doesn't involve m (Model), so struts can take whatever form of business logic that Java implements. Spring Spring is a lightweight container (Light-weight container). At its core is the Bean Factory (beanfactory). To construct the M (Model) we need. On this basis,
Spring provides the implementation of AOP (aspect-orientedprogramming, level-oriented programming) to provide services such as transactional, security, and so on, in a non-managed environment. The expansion of the Bean factory applicationcontext more convenient for us to implement the application of the Java EE, the implementation of Dao/orm is convenient for us to develop the database; Web MVC and the spring Web provide Java The framework for Web applications or integration with other popular web frameworks. This means that they can be used together to complement each other's own characteristics.
Hibernate hibernate is a free open-source Java package that makes the relational database
It is easy to deal with. Just like your database includes ordinary Java objects that you use every day, you don't have to think about how to take them out of a magical database table at the same time (or put them back in a database table).
It frees you. Enables you to focus on the objects and functions of your application without worrying about how to save them or how to find them later. EJB a Technical specification: EJB is technically not a "product" EJB is a standard description of the building of application components to be addressed: extensible (Scalable) distributed (distributed) transactional (transactional) data storage (Persis Tent) security (secure) Ant-Ant Simple Introduction
Ant is a make-like tool for compiling/executing/testing Java programs. Almost everything in the construction, packaging, and publishing process can be handled by Ant's Task. Two Ant installation and configuration you can download pre-compiled ant from the Jakata site, unzip it to any folder, and set your own environment variables. namely Ant_home, point to unzip the folder; Set the JAVA_HOME environment variable to point to the root folder of the JDK; Three: Using Ant to manage a project ant starts with its own initiative to load a project configuration file called Build.xml. Suppose you want to give this project configuration file a different name. You can use the buildfile tag to execute ant, like this: Ant-buildfile project_configuration.xml main Features: Use an XML file as a configuration file, or build.xml; can be seamlessly integrated with JUnit To achieve the system test, compile to the advertised function. Powerful, specific report function; Flexible control. You can define the combination of tasks that you want to run.7 Struts2 Implementing MVC
Struts uses JSP as a view of MVC, with the action action class specified by Actionservlet as the Controller, C in MVC, responsible for the interaction between the view and the model. Each entry point of the controller is set by a configuration file named Struts-config.xml. This file maps requests from views into specific Java classes for corresponding processing. The controller also specifies the location of the next view.
The model in struts mainly refers to the JavaBean. It is the representative of the model, primarily encapsulating data and business logic.8 Struts1 Process:
The controller initializes the operation, reads the configuration file, initializes the corresponding Moduleconfig object for different struts modules. The controller receives the HTTP request and finds the action subclass corresponding to the request from Actionconfig, assuming that there is no corresponding action, the controller forwards the request directly to the JSP or static page, otherwise the controller distributes the request to the detailed action class for processing. Before the controller invokes the Execute method of the detailed action, the Actionform object will populate itself with the parameters in the HTTP request. It is also possible to call the Validate method in the Actionform class to check the legitimacy of the request parameters. and the ability to return a Actionerrors object that includes all error messages. Run the detailed Execute method. It is responsible for running the appropriate business logic.
When you are finished running. Returns a Actionforward object that the controller uses to forward work through the Actionforward object. It is also possible to encapsulate the business logic that the action is dealing with in JavaBean, assuming that there is an EJB in the system, then call the EJB through JavaBean to complete the business process. Assuming there is no EJB, then directly in the JavaBean database connection, database-related operations.
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
Struts2 and Struts1 know
Start building with 50+ products and up to 12 months usage for Elastic Compute Service