1.struts Development Steps
- The introduction of struts's jar package;
- The core functions of struts are introduced in Web. XML, and the Struts core filter is configured.
- Development action, generally inherited from Actionsupport, the business method must return a string type, the method cannot have parameters;
- Configure the action in Src/struts.xml;
2.struts Execution Process
Server Startup
- Load the project's web. xml;
- Create a struts core filter object and execute its init () method, reading Struts-default.xml, Struts-plugin.xml, and struts.xml configuration files sequentially;
Access
- The user accesses the action, and the server creates an action instance based on the access URL to find the corresponding action class;
- Execute Struts Interceptor;
- Each subsequent visit creates an instance of the action and then executes the interceptor;
3.struts-default.xml detailed
- The bean node develops the node type that struts creates at run time;
- Specifies the Struts-default package that the package in the user-written struts.xml must inherit from.
These include:
- The result type of the jump
Dispathcer: Default Value
Redirect: redirect
Redirectaction: Redirect to Action resource
Stream: used when downloading files
- 32 interceptors are defined, and for convenience of reference, the Interceptor can be referenced by means of a stack definition;
- The default execution of interceptors (8), executed sequentially;
- Action of the default value type;
4. Interceptor vs Filter
Interceptors and filters play a role in intercepting resources.
Filter:
Intercept all resources: JSP, servlet, CSS, JS and so on;
Can be used in all servlet projects;
Interceptors:
Only action requests can be intercepted;
Is the concept of struts and can only be used in struts projects;
The application framework based on MVC pattern struts (1)