Today a friend asked me if Action in Struts2 must implement the execute method? The answer was smoothly.
There are actually two situations:
1) If your Action class inherits from ActionSupport or BaseAction, to be precise, it has rewritten the execute method. The default implementation in ActionSupport is to return the "success" view. Therefore, you can not implement the execute method, as long as your struts.xml has the result corresponding to "success".
<action name="doRevenuesMaintenance"> <interceptor-ref name="novatar-webStack-baseparam"> <param name="security.actionType">PRIVATE</param> </interceptor-ref> <result name="success">incomeMaintenance.jsp</result> < /action>
In this code, the jump page is controlled through the action configuration file. There is no execute() method override in the action class.
2) If your Action class does not inherit ActionSupport or BaseAction, and you do not specify your own method in the corresponding <action> tag in struts.xml, you must find the execute method by default. At this time, you must implement the execute method, otherwise Struts2 will not find the corresponding method and report an error.
However, in most cases, ActionSupport is inherited (for example, input verification, file upload and other functions require inheritance). Also, no matter whether you write the execute method or not, you can still use the method attribute of the <action> tag to specify other methods.
The above is a related introduction to whether the Execute method needs to be implemented in Struts2 Action introduced to you. I hope it will be helpful to you!