具体视图的返回可以由用户自己定义的Action来决定

具体的手段是根据返回的字符串找到对应的配置项,来决定视图的内容

具体Action的实现可以是一个普通的java类,里面有public String execute方法即可或者实现Action接口

不过最常用的是从ActionSupport继承,好处在于可以直接使用Struts2封装好的方法


1、web.xml配置为基本配置(见上一篇博客)

2、struts.xml配置

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

注意action中多了一个class的路径在src下创建一个包com.wxh.action(名字可以随意),此处的java类有三种写法.

package com.wxh.action;
public class IndexAction1 {
	public String execute(){
		return "success";
	}
}
package com.wxh.action;
import com.opensymphony.xwork2.Action;
public class IndexAction2 implements Action{
	public String execute(){
		return "success";
	}
}
package com.wxh.action;
import com.opensymphony.xwork2.ActionSupport;
//这个是默认执行的class
public class IndexAction3 extends ActionSupport{	
	@Override
	public String execute(){
		return "success";
	}
}
Struts2 Action_其他