struts2_action标签中的class属性

struts2_action标签中的class属性,

如果不写,默认调用ActionSupport对象,调用它的execute()方法,固定返回“success”。

可以写调用java类

<action name="index" class="com.bjsxt.struts2.front.action.IndexAction3">
            <result name="success">/ActionIntroduction.jsp</result>
        </action>
View Code

这个java类有三种写法:

1、普通java类

package com.bjsxt.struts2.front.action;

public class IndexAction1 {
    public String execute() {
        return "success";
    }
}
View Code

2、实现Action接口

package com.bjsxt.struts2.front.action;

import com.opensymphony.xwork2.Action;

public class IndexAction2 implements Action {
    @Override
    public String execute() {
        return "success";
    }
}
View Code

3、继承ActionSupport类

package com.bjsxt.struts2.front.action;

import com.opensymphony.xwork2.ActionSupport;

public class IndexAction3 extends ActionSupport {
    
    @Override
    public String execute() {
        return "success";
    }
}
View Code

我们只用第三种,因为ActionSupport类写好了一系列将来可能用到的方法。

posted @ 2017-04-11 16:58  半缘修道半缘(君)  阅读(2413)  评论(0编辑  收藏  举报