The result set type in Struts2
- 2020-04-01 01:40:06
- OfStack
1. Each action method returns a value of type String, which determines what value struts returns on a request.
2. In the configuration file, each action element must be configured with a result element, and each result corresponds to the return value of an action.
3. Result has two properties:
Name: the name of the result, like the return value in the action, with the default value of success;
Type: response result type with a default value of dispatcher.
In the < img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201304/2013041117040629.jpg "> find below the struts - default. XML file, as shown in the following:
< img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201304/2013041117040630.jpg ">
Description:
1. It can be seen from the above that there are a total of 10 types
2. The default type is ServletDispatcherResult, that is, forward.
3. The result type can be any one of the 10 result types.
Dispatcher type (1), descriptionThe Dispatcher type is the most commonly used result type and the default result type of the struts framework.
(2) examplesPage reference: /manager/index.jsp
For Action see: AdminAction
Configuration file: struts.xml
In a configuration file, you can write it in two ways:
< img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201304/2013041117040631.jpg ">
The following illustration illustrates the origin of the location:
< img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201304/2013041117040631.jpg ">
View the source code:
< img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201304/2013041117040632.jpg ">
Redirect is a Redirect. If you use the redirect type, the value in the reuqest scope cannot be passed to the foreground.
RedirectAction type (1), description1. Redirect the result type to the action
2. Two parameters are acceptable
A) ActionName: action name
B) -sheldon: no, I didn't
The first way:
< Result the name = "success" type = "redirectAction >" Resulttype/redirectactionAction. Action< / result>
The second way:
< Result the name = "success" type = "redirectAction >"
< ! --
ActionName:
The path of the requested action
The namespace:
If it is not written, the default is the path of the requested action, and if it is written, the path is reassigned
- >
< Param name = "actionName" >
Resulttype/redirectactionAction. Action
< / param>
< / result>
(2) examplesThe first way:
< Result the name = "success" type = "redirectAction >" Resulttype/redirectactionAction. Action< / result>
The second way:
< Result the name = "success" type = "redirectAction >"
< ! --
ActionName:
The path of the requested action
The namespace:
If it is not written, the default is the path of the requested action, and if it is written, the path is 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, get the request URI of the path, for example, the url is: http://server/struts2/path1/path2/path3/test.action
2. First, find the package whose namespace is /path1/path2/path3. If the package exists, then find the action named test in the package. If the package does not exist, then go to step 3.
3. Find the package whose namespace is /path1/path2. If the package exists, then find the action named test in the package. If the package does not exist, then go to step 4.
4. Look for the package namespace as /path1, if the package exists, then find the action named test in the package, if the package still does not exist, go to the default namaspace package below to find the action named test (the default namespace is empty string ""), if still can not find, the page prompt can not find the action.
Struts 2 Action prototype
The Prototype Prototype Each request creates a new Action object
< img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201304/2013041117040633.jpg ">
The Servlet
The Singleton prototype When first requested, the servlet object is created and then used each time.
The life cycle of servlets
Create - init - service - destory