Multiple action and multiple package share a view-global result configuration

Source: Internet
Author: User
Java EE Development of various resources download list, the history of the most IT resources, personal collection summary.


When the same view is used in more than one action, we should define result as a global view. Similar functionality is also available in the global forward,struts2 provided in STRUTS1:
<package name= "Package1" >
<global-results>
<result name= "Message" >/message.jsp</result>

</global-results>

<action name= "Action1" ></action>

<action name= "Action2" ></action>

</package>

At this point, the action class for Action1 and Action2 under the Package1 package can access the message attempt. However, the <global-result> <result> in this area can only be shared under the same package, and if you want to share between different package, you may inherit another package B with one package a. Package A can use the global result and <action> defined in Pack B, and, of course, if you can overwrite <action> or <result> in the parent bundle B
  such as: <package name= "Itstar" namespace= "/student" extends= "Struts-default";
          <global-results>
              <result type= "redirect" Name= "Success" >/SUCCESS.JSP</RESULT>
         </global-results>
    </package>   
   <package name= "Itcast" namespace= "/test" extends= " Itstar ";
       <action name= "delete" class= "",
      </action>
   </package>

This time, in the browser input: Http://localhost:8080/test/delete, you can jump to the "/success.jsp" page.

Here <action name= "Delete" > does not write <result>, but the default values for the <action> and <result> properties are:

1> if no class or empty string is specified for the action, the default is Com.opensymphony.xwork2.ActionSupport.

2> If no method is specified for the action or is an empty string, the Execute () method in action is executed by default.

3> if the Name property of result is not specified or is an empty string, the default value is success.

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.