1、struts2流程: jsp页面-->web.xml-->struts.xml-->user.acrion-->UserAction.java 中的execute()--result
所以struts2中默认调用execute()方法。
2、Action中也可以自定义方法,只要在action的method属性选择,就可以利用该方法替换execute方法的作用。
struts.xml:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<action name="login" class="com.shensiyuan.struts.action.LoginAction" method="MyExecute">
<result name="success">/result.jsp</result>
</action>
LoginAction.java:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
@Override public String execute(){ return "success"; } public String MyExecute(){ System.out.println("MyExecute invoke!!!"); return SUCCESS; }
注意:在开发中不推荐在Action中自定义多个方法,多个模块使用同一个Action,因为容易造成代码混乱,影响阅读和修改!