First, action default configuration value
<span style= "FONT-SIZE:18PX;" ><package name= "Itcast" namespace= "/test" extends= "Struts-default" > <action name= "HelloWorld" class = "Cn.itcast.action.HelloWorldAction" method= "execute" ><result name= "Success" >/web-inf/page/hello.jsp </result> </action> </package> 1> Assuming no class is specified for action, the default is Actionsupport.2> assumes that no method is specified for the action, and the Execute () method in the action is run by default. 3> assumes that the name property of result is not specified. The default value is success. </span>
Ii. various forwarding types of result in action
<span style= "FONT-SIZE:18PX;" ><action name= "HelloWorld" class= "cn.itcast.action.HelloWorldAction" ><result name= "Success" >/ Web-inf/page/hello.jsp</result></action>
(1) The result configuration is similar to forward in Struts1, but several result types are available in struts2, often using the following types: Dispatcher (default), redirect, Redirectaction, plaintext.
(2) In result, you can also use the ${property name} expression to access the property in the action, and the property name in the expression corresponding to the property in the action. For example, the following:
<result type= "redirect" >/view.jsp?id=${id}</result>
(3) The following is a sample of the redirectaction result type, assuming that the redirected action is under the same package:
<action name= "redirectaction" ><result type= "Redirectaction" >helloworld</result></action>
Assume that the redirected action is under another namespace:
<struts> <package name= "Itcast" namespace= "/control/employee" extends= "base" ><action name= "list "Class=" Cn.itcast.action.HelloWorldAction "method=" execute "><result name=" Success "type=" redirect ">/ Employeeadd.jsp?username=${username}</result></action><action name= "redirect" ><result type= "Redirect" >/employeeadd.jsp</result></action><action name= "Redirectaction" > <!-- --><result type= "redirectaction" ><param name= "ActionName" under different namespaces >xxx</param> <!-- Action's name--><param name= "namespace" >/control/department</param></result></action> </package><package name= "Other" namespace= "/control/department" extends= "base" ><action name= "xxx" ><result>/WEB-INF/page/hello.jsp</result></action></package></struts>
(4) PlainText: Display the original file content, such as: when we need to display the JSP file source code. We are able to use this type.
<result name= "source" type= "plaintext" ><param name= "location" >/xxx.jsp</param><param name= " CharSet ">UTF-8</param><!--Specifies the encoding of the read file--></result>
Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.
"STRUTS2 Study notes (2)" Action Default and configuration action to result various forwarding types