Action类的三种写法
* Action类就是一个POJO类
POJO(Plain Ordinary Java Object)简单的Java对象。理解记:没有继承、也没有实现接口,就是POJO类。
/**
* POJO类: 没有任何继承和实现
* @author Administrator
*/
public class Demo1Action {
/**
* execute是默认方法
* return null; 不会进行跳转
* @return
*/
public String execute() {
System.out.println("Demo1Action是POJO类...");
return null;
}
}
* Action类可以实现Action接口
* 在Action接口中定义了5个常量,常量的值对应的是5个逻辑视图跳转页面(跳转的需要自己配置),还定义了一个execute方法。
* 5个逻辑视图的常量
* SUCCESS --- 成功
* INPUT --- 用于数据表单校验,如果校验失败,跳转到INPUT视图
* LOGIN --- 登录
* ERROR --- 错误
* NONE --- 页面不跳转
/**
* 实现Action的接口,Action是框架提供的接口
* @author Administrator
*/
public class Demo2Action implements Action {
public String execute() throws Exception {
System.out.println("Demo2Action实现了Action接口");
//表示页面不跳转
return NONE;
}
}
* Action类可以去继承ActionSupport类(开发中使用最多)
/**
* 编写Action类继承ActionSupport类,ActionSupport类已经实现了Action和其他接口
* @author Administrator
*/
public class Demo3Action extends ActionSupport {
public String execute() throws Exception {
System.out.println("Demo3Action继承了ActionSupport类...");
return NONE;
}
}
注意:写完Action类记得配置struts.xml