"STRUTS2 Study notes (2)" Action Default and configuration action to result various forwarding types

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.