1. Each action method returns a value of type String. The value returned by Struts in a request is determined by this value.
2. In the configuration file, the configuration of each action element must have a result element, and each result corresponds to the return value of an action.
3. Result has two attributes:
name: The name of the result, which is the same as the return value in the action. The default value is success;
type: response result type, the default value is dispatcher.
Find below the struts-default.xml file as shown below:
illustrate:
1. From the above, it can be seen that there are a total of 10 types
2. The default type is ServletDispatcherResult, which is forwarding.
3. The result type can be any of these 10 result types.
Dispatcher type (1), descriptionThe Dispatcher type is the most commonly used result type and is also the default result type of the struts framework.
(2), ExamplePage reference:/manager/index.jsp
Action reference: AdminAction
Configuration file: struts.xml
In the configuration file, there are two ways of writing:
The following figure illustrates the origin of location:
View source code:
Redirect is a redirection. If the redirect type is used, the value in the reuqest scope cannot be passed to the front end.
redirectAction type (1), description1. Redirect the result type to action
2. Two parameters can be accepted
a)actionName: the name of the action
b) namespace: namespace
First way:
<result name="success" type="redirectAction">resulttype/redirectactionAction.action</result>
Second way:
<result name="success" type="redirectAction">
<!--
actionName:
The path of the requested action
namespace:
If not written, the default is the path of the requested action. If written, the path will be reassigned.
-->
<param name="actionName">
resulttype/redirectactionAction.action
</param>
</result>
First way:
<result name="success" type="redirectAction">resulttype/redirectactionAction.action</result>
Second way:
<result name="success"type="redirectAction">
<!--
actionName:
The path of the requested action
namespace:
If not written, the default is the path of the requested action. If written, the path will be reassigned.
-->
<paramname="actionName">
resulttype/redirectactionAction.action
</param>
</result>
<package name=”ss” namespace=”/csdn/csdn”>
<action="delete">
</package>
<package name=”test” namespace=”/csdn”>
<action="delete">
</package>
<package name=”sss” namespace=””>
<action="delete">
</package>
Search order for action names
1. Obtain the URI of the request path. For example, the url is: http://server/struts2/path1/path2/path3/test.action
2. First, look for the package whose namespace is /path1/path2/path3. If this package exists, search for the action named test in this package. If this package does not exist, go to step 3;
3. Look for the package whose namespace is /path1/path2. If this package exists, search for the action named test in this package. If this package does not exist, go to step 4;
4. Look for the package with namespace /path1. If this package exists, look for the action named test in this package. If this package still does not exist, go to the default namaspace package to find the action named test (default The namespace is an empty string ""). If it is still not found, the page prompts that the action cannot be found.
Action prototype struts2
The prototype prototype creates a new Action object for each request.
Servlet
When the Singleton prototype is requested for the first time, you can create the servlet object and use the object every time.
Servlet life cycle
create---init---service---destroy