Structs2 dynamic method call and structs2 dynamic call

Source: Internet
Author: User

Structs2 dynamic method call and structs2 dynamic call

First, specify the Method attribute (more actions)

<! -- Declaration package -->
<Package name = "user" extends = "struts-default">

<! -- Define action -->

<Action name = "first" class = "com. sxt. action. UserAction" method = "first">

<! -- Define the ing page after successful processing -->

<Result name = "first"> first. jsp </result>
</Action>

<Action name = "second" class = "com. sxt. action. UserAction" method = "second">
<Result name = "second"> second. jsp </result>
</Action>

<Action name = "third" class = "com. sxt. action. UserAction" method = "third">
<Result name = "third"> first. jsp </result>
</Action>

</Package>

Method 2: Exclamation mark (switch required) This method is not recommended on the official website.

(1) Enable and define Action in Structs2

<Constant name = "struts. enable. DynamicMethodInvocation" value = "true"/>

<Action name = "userAction" class = "com. sxt. action. UserAction">
<! -- Define the ing page after successful processing -->
<Result name = "add"> user_add.jsp </result>
<Result name = "update"> user_update.jsp </result>
</Action>

(2) In index. jsp

<A href = "userAction! Add "> add User </a>
<A href = "userAction! Update "> modify a user </a>

(3) create an Action object named UserAction

Public class UserAction extends ActionSupport {

Public String add (){

Return "add ";

}

Public String update (){

Return "update ";

}

}

Third: wildcard (officially recommended)

(1) jsp page

<A href = "useraddAction"> Add a user </a>
<A href = "userupdateAction! "> Modify a user </a>

(2) define Action in Structs2.xml

<Action name = "user * Action" class = "com. sxt. action. UserAction" method = "{1}">
<! -- Define the ing page after successful processing -->
<Result name = "add"> user_add.jsp </result>
<Result name = "update"> user_update.jsp </result>
</Action>

 

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.