Struts2
After learning the basics of JAVA, you must face the learning of three major frameworks. As a beginner, you must understand the principles of the three major frameworks. The design purpose is the primary task. Only after grasping the design purpose of the framework can you learn and use the framework in a targeted manner. Here we will introduce the strue2 framework.
What is Struts2?
Struts2 is a very excellent MVC framework, based on Model2 design model
Developed from the two classic frameworks of traditional Struts1 and WebWork
Strust2 core features
(1) Allow POJO (Plain Old Java Objects) objects as Action
(2) Action's execute method is no longer coupled with the Servlet API, making it easier to test
(3) Support more view technologies (JSP, FreeMarker, Velocity)
(4) Interceptor mechanism based on Spring AOP idea is easier to expand
(5) More powerful and easier to use input verification function
The result node of the struts2 configuration file
The result node is a child of the action node, which represents a destination that may be visited after the action method is executed;
The Action method name corresponds to the method attribute of the action node;
Each Action method will return a String value and correspond to the name attribute of the result node one by one. The result node determines the response different results based on the name attribute value;
The result node has two properties, name (the name of the result, that is, the return value of the action method, default is SUCCESS) and type (the type of the response result, default is dispatcher)
As shown in circle 1 in the above figure, the value of the result node represents a destination that the struts2 request will go to.
result node's result type (type)
dispatcher (forward)
dispatcher is the default result type of the struts2 framework and is also the most commonly used result type. This type has a default parameter location, which is generally omitted. The following two writing methods are equivalent:
The dispatcher result type forwards control to the specified resource in the application. If you need to forward control to an external resource, you should use the redirect result type
redirect (redirect)
chain (forward to an action)
redirectAction (redirect to an action)
Wildcard mapping
struts2 provides a wildcard mapping mechanism to simplify multiple mapping relationships similar to each other into one mapping relationship
Wildcard mapping rules
As shown in the figure, in the first package, * can represent four of them in the second package.
Summarize
The above is the entire content of this article. I hope that the content of this article has certain reference value for everyone's study or work. If you have any questions, you can leave a message to communicate. Thank you for your support to Wulin.com.