struts2内Action方法调用

1、struts2流程: jsp页面-->web.xml-->struts.xml-->user.acrion-->UserAction.java 中的execute()--result

所以struts2中默认调用execute()方法。

2、Action中也可以自定义方法,只要在action的method属性选择,就可以利用该方法替换execute方法的作用。

struts.xml:

<action name="login" class="com.shensiyuan.struts.action.LoginAction" method="MyExecute">
            <result name="success">/result.jsp</result>
        </action>
View Code

LoginAction.java:

    @Override
    public String execute(){
        return "success";
    }
    public String MyExecute(){
        System.out.println("MyExecute invoke!!!");
        return SUCCESS;
    }
View Code

注意:在开发中不推荐在Action中自定义多个方法,多个模块使用同一个Action,因为容易造成代码混乱,影响阅读和修改!

posted @ 2016-03-10 21:41  guodaxia  阅读(428)  评论(0编辑  收藏  举报