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>