我是靠谱客的博主 粗犷雪碧,这篇文章主要介绍Struts2中Action的三种编写方式,现在分享给大家,希望可以做个参考。

ActionDemo1.java

复制代码
1
2
3
4
5
6
7
8
9
10
11
/** * Action的编写方式:Action类是一个POJO的类 * @author zhang * */ public class ActionDemo1 { public String execute() { System.out.println("ActionDemo1执行了..."); return null; } }

ActionDemo2.java

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import com.opensymphony.xwork2.Action; /** * Action的编写方式二:实现一个Action的接口 * * 实现接口的这种方式,提供了五个常量(五个逻辑视图名称) * * SUCCESS :成功 * * ERROR :失败 * * LOGIN :登陆出错页面跳转 * * INPUT :表单校验的时候出错 * * NONE * @author zhang * */ public class ActionDemo2 implements Action{ @Override public String execute() throws Exception { System.out.println("ActionDemo2执行了..."); return null; } }

ActionDemo3.java

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import com.opensymphony.xwork2.ActionSupport; /** * Action的编写方式三:Action类继承ACtionSupport类 * * 推荐使用继承ActionSupport方式 * * 提供了数据校验,国际化等一系列操作的方法 * @author zhang * */ public class ActionDemo3 extends ActionSupport{ @Override public String execute() throws Exception { System.out.println("ActionDemo3执行了..."); return NONE; } }

 

最后

以上就是粗犷雪碧最近收集整理的关于Struts2中Action的三种编写方式的全部内容,更多相关Struts2中Action内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(53)

评论列表共有 0 条评论

立即
投稿
返回
顶部