struts2--Overview

Introduction to struts2 framework:
Framework:
a semi-finished product (that is, a part of the function is completed), which can improve the development efficiency of the sequence.

Mainstream frameworks: ssh, ssi

Overview:
struts2 is a framework applied to the web layer in the three-layer ( web layer, business logic layer, and persistence layer ) structure of javaee, which itself conforms to the mvc idea (****);
the business logic layer in the development of learning later is composed of Instead of spring, the persistence layer is replaced by Hibernate; struts2 is developed on the basis of struts1 and webwork.

Features of the web layer framework (*****): The
web layer framework has front-end controllers (filters), and the front-end controllers make different requests go to different methods.

1. Jar package:
You can import according to the jar package in the project written by others: struts-2.3.15.3-all\struts-2.3.15.3\apps-->struts2-blank.war in lib in all jar packages Copy directly to the lib folder in the project.
2. Configure the filter:
struts-2.3.15.3-all\struts-2.3.15.3\apps\struts2-blank\WEB-INF-->web.xml to copy
 <filter>
        <filter-name>struts2</filter- name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url- pattern>/*</url-pattern>
    </filter-mapping>
3. Configure the access path of action: actually configure struts.xml

Struts2 running process:
request ---- reach StrutsPrepareAndExecuteFilter core controller ----- Interceptors interceptor (implement code function), intercept the corresponding action ----- Action's execute (the action class uses reflection to get the action's class, get the execute() method through the getMethod() method, and let invoke() execute the return value to match the result) --- Result page Result
* The interceptor is defined in struts-default.xml
* The execution interceptor is defaultStack reference interceptor

dtd addition:
1. In case of network disconnection 2. There is a struts-2.3.dtd file under the struts2-core-2.3.15.3.jar package of the program, copy it to a folder. Then configure the Catalog .
Note:
key type: select schema location
key: find the corresponding constraint namespace copy URL address.
If there is a problem, you can remove All cache constraint configuration in Cache.

 

The loading order of struts2's configuration file: the
request goes through the filter first, and in the filter, it goes through the interceptor first.
            init_DefaultProperties(); // [1] ---------- org/apache/struts2/default.properties
            init_TraditionalXmlConfigurations(); // [2] --- struts-default.xml (configuration interceptor) ,struts-plugin.xml (plugin), struts.xml (configuration action) (**) can modify the constant
            init_LegacyStrutsProperties() of struts2; // [3] --- Create struts.properties under src, you can modify struts2 constant. (**)
            init_CustomConfigurationProviders(); // [5] ----- Custom configuration providers
            init_FilterInitParameters() ; // [6] ----- web.xml (**)
            init_AliasStandardObjects() ; // [ 7] ---- Bean loading
In struts.xml, struts.properties, web.xml, if the same struts constant is modified at the same time, the modification in web.xml shall prevail.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326645571&siteId=291194637