【Struts2复习知识点三】Action的配置

具体视图的返回可以由用户自己定义的Action来决定
具体的手段是根据返回的字符串找到对应的配置项,来决定视图的内容
具体Action的实现可以是一个普通的java类,里面有public String execute方法即可
或者实现Action接口
不过最常用的是从ActionSupport继承,好处在于可以直接使用Struts2封装好的方法

struts.xml

View Code
<constant name="struts.devMode" value="true" />
<package name="front" extends="struts-default" namespace="/">
<action name="index" class="com.bjsxt.struts2.front.action.IndexAction1">
<result name="success">/ActionIntroduction.jsp</result>
</action>
</package>

IndexAction1.java

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

IndexAction2.java

View Code
import com.opensymphony.xwork2.Action;

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

IndexAction3.java

View Code
import com.opensymphony.xwork2.ActionSupport;

public class IndexAction3 extends ActionSupport {

@Override
public String execute() {
return "success";
}
}



原文地址:https://www.cnblogs.com/surge/p/2362079.html