Struts2系列笔记(3)---Action类的3种书写方式
来源:互联网 发布:js实现继承有哪些方式 编辑:程序博客网 时间:2024/06/07 06:47
Action类的3种书写方式
本文主要写有关写Action类的3种书写方式:
(1)第一种 Action可以是POJO(简单模型对象) 不需要继承任何父类 也不需要实现任何接口
(2)实现Action接口
(3)继承ActionSupport(推荐)
那我们先来书写第一种:
(1)第一种 Action可以是POJO (简单模型对象) 不需要继承任何父类 也不需要实现任何接口
1 //这里其实就是一个普通的类,类里面的方法可以任意写,如果写execute()方法那就代表默认执行它2 public class RequestAction1 { 3 //提供满足条件的方法 excute方法4 //public 范围的 带有String返回值的 无参的方法5 public String execute(){6 System.out.println("测试方式一");7 return null;//null表示不进行跳转8 }9 }
(2)实现Action接口
1 import com.opensymphony.xwork2.Action; 2 public class RequestAction2 implements Action{ 3 4 public String execute() throws Exception { 5 System.out.println("方式二 实现Action接口 成功执行...."); 6 return SUCCESS; 7 } 8 } 9 /**10 * Action接口中一共有5个五种逻辑视图 和一个方法分别如些:11 * public abstract interface com.opensymphony.xwork2.Action {12 数据处理成功(成功的跳转页面)13 public static final java.lang.String SUCCESS = "success";14 页面不进行跳转 return null 15 public static final java.lang.String NONE = "none";16 数据处理发送错误(错误页面)17 public static final java.lang.String ERROR = "error";18 用户处理数据 数据有误 用于表单的校验19 public static final java.lang.String INPUT = "input";20 主要是权限认证21 public static final java.lang.String LOGIN = "login";22 23 public abstract java.lang.String execute() throws java.lang.Exception;24 }25 */
(3)继承ActionSupport(推荐)
1 import com.opensymphony.xwork2.Action; 2 import com.opensymphony.xwork2.ActionSupport; 3 //为什么推荐ActionSupport,在Action中如果使用基础ActionSupport的方式 可以使用表单的校验 错误信息的设置 和国际化信息 三个重要的功能。 4 public class RequestAction3 extends ActionSupport { 5 @Override 6 public String execute() throws Exception { 7 System.out.println("方式三 继承ActionSupport完成 书写"); 8 return super.execute();//返回SUCCESS 9 }10 }11 /**ActionSupport类的特点,点进去发现它实现了许多的接口12 * public class ActionSupport implements Action, Validateable, 13 * ValidationAware, TextProvider, LocaleProvider, Serializable14 * 这么多接口说明它不简单15 * 16 */
关于action类的创建我就说这么多!请大家多指点!
0 0
- Struts2系列笔记(3)---Action类的3种书写方式
- Struts2系列笔记(3)---Action类的3种书写方式
- Struts2系列笔记(3)---Action类的3种书写方式
- Struts2系列笔记(3)---Action类的3种书写方式
- Struts2系列笔记(3)---Action类的3种书写方式
- struts2让一个类成为 action的3种方式
- struts2中action的3种实现方式
- struts2中action编写的3种方式
- Struts2-Action-5-系列问题(接受用户输入(3种方式))
- Struts2让一个类成为一个Action的3种方式
- Struts2 in action 笔记3
- Struts2第九讲学习笔记Action的三种实现方式,两种驱动方式
- Struts2配置action的几种方式
- struts2--Action的四种配置方式
- struts2创建Action的三种方式
- Struts2 action的三种实现方式
- Struts2:action的三种开发方式
- struts2系列学习笔记(4)---------------Action的多样化配置之一
- uniqueResult的用法
- HTML 五角星 -- CSS
- PCL1.8.0+VS2013配置教程
- 自定义控件笔记(1)
- C primer plus 第六章 循环 编程练习
- Struts2系列笔记(3)---Action类的3种书写方式
- Redis 3.0 for Windows Document
- LSTM
- sublime批量处理excel数据
- JavaSE_22th_抽象类
- JavaScript属性的特性
- 欢迎使用CSDN-markdown编辑器
- LeetCode - 13. Roman to Integer
- 摘要认证