Action Learning Note 2-there is a discussion about the action method. The execute method is not necessarily executed when the Action is executed. You can use method = to specify the method to be executed when configuring the Action in the configuration file.
You can also dynamically specify the url address (dynamic method call DMI) (recommended)
Method 1
<Struts> <constant name = "struts. devMode "value =" true "/> <package name =" user "extends =" struts-default "namespace ="/user "> // method 1 <action name =" userAdd "class =" com. struts2.user. action. userAction "method =" add "> <result>/user_add_success.jsp </result> </action> // method 2 <action name =" user "class =" com. struts2.user. action. userAction "> <result>/user_add_success.jsp </result> </action> </package> </struts> <span style =" font-family: Arial, Helvetica, sans-serif; "> </span>
package com.bjsxt.struts2.user.action; import com.opensymphony.xwork2.ActionSupport; public class UserAction extends ActionSupport {public String add() {return SUCCESS;} }
Call method: http: // localhost: 8080/Struts2_0500_ActionMethod // user/userAdd
Method 2: the former will produce too many actions, so it is not recommended to use
Call method: http: // localhost: 8080/Struts2_0500_ActionMethod/user! Add
DMI dynamic method call;
Method 2