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類寫好了一系列將來可能用到的方法。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM