structs实现三种action的方法
第一种:一般类,带有public String execute()方法。
另外一种:继承LoginActionInterface implements Action接口的类。
第三种:继承LoginActionSupport extends ActionSupport抽象类的类。
结构图
三个类的详细写法,也贴上来供大家參考
package com.test.action; import com.test.dao.UserCheck;
import com.test.vo.User; public class LoginAction {
private String username;
public String getUsername() {
return username;
} public void setUsername(String username) {
this.username = username;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} private String password; public String execute()
{
User u=new User();
u.setUsername(this.getUsername());
u.setPassword(this.getPassword()); /*调用业务逻辑层代码*/
UserCheck check=new UserCheck();
if(check.login(u))
{
return "login_ok";
}
else
{
return "login_fail";
} }
}
package com.test.action; import com.opensymphony.xwork2.Action;
import com.test.dao.UserCheck;
import com.test.vo.User; public class LoginActionInterface implements Action{
private String username;
public String getUsername() {
return username;
} public void setUsername(String username) {
this.username = username;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} private String password; public String execute()
{
User u=new User();
u.setUsername(this.getUsername());
u.setPassword(this.getPassword()); /*调用业务逻辑层代码*/
UserCheck check=new UserCheck();
if(check.login(u))
{
return "login_ok";
}
else
{
return "login_fail";
} }
}
package com.test.action; import com.opensymphony.xwork2.ActionSupport;
import com.test.dao.UserCheck;
import com.test.vo.User; public class LoginActionSupport extends ActionSupport{ /**
*
*/
private static final long serialVersionUID = 1L;
public LoginActionSupport()
{
System.out.println("LoginActionSupport");
}
private String username;
public String getUsername() {
return username;
} public void setUsername(String username) {
this.username = username;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} private String password; public String execute()
{
User u=new User();
u.setUsername(this.getUsername());
u.setPassword(this.getPassword()); /*调用业务逻辑层代码*/
UserCheck check=new UserCheck();
if(check.login(u))
{
return "login_ok";
}
else
{
return "login_fail";
} }
}
事实上我们发现。仅仅要具有public String execute()这种方法即可了。还要注意,在继承ActionSupport的时候。默认的execute()是返回success。
structs实现三种action的方法的更多相关文章
- .Net MVC 导入导出Excel总结(三种导出Excel方法,一种导入Excel方法) 通过MVC控制器导出导入Excel文件(可用于java SSH架构)
.Net MVC 导入导出Excel总结(三种导出Excel方法,一种导入Excel方法) [原文地址] 通过MVC控制器导出导入Excel文件(可用于java SSH架构) public cl ...
- JSON三种数据解析方法(转)
原 JSON三种数据解析方法 2018年01月15日 13:05:01 zhoujiang2012 阅读数:7896 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blo ...
- 同源策略(same-origin policy)及三种跨域方法
同源策略(same-origin policy)及三种跨域方法 1.同源策略 含义: 同源是指文档的来源相同,主要包括三个方面 协议 主机 载入文档的URL端口 所以同源策略就是指脚本只能读取和所属文 ...
- 以用户名注册来分析三种Action获取数据的方式
1.注入属性 直接注入属性: public String userName; public String getUserName() { return userName; } public void ...
- halcon三种模板匹配方法
halcon有三种模板匹配方法:即Component-Based.Gray-Value-Based.Shaped_based,分别是基于组件(或成分.元素)的匹配,基于灰度值的匹配和基于形状的匹配,此 ...
- iOS——浅谈iOS中三种生成随机数方法
ios 有如下三种随机数方法:
- Sencha 基础Demo测试,三种showView的方法
直接贴代码吧 Ext.define("build.controller.MainController",{ extend:"Ext.app.Controller" ...
- Entity Framework关联实体的三种加载方法
推荐文章 EF性能之关联加载 总结很好 一:介绍三种加载方式 Entity Framework作为一个优秀的ORM框架,它使得操作数据库就像操作内存中的数据一样,但是这种抽象是有性能代价的,故鱼和熊掌 ...
- List 三种遍历的方法
学习java语言list遍历的三种方法,顺便测试各种遍历方法的性能,测试方法为在ArrayList中插入1千万条记录,然后遍历ArrayList,发现了一个奇怪的现象,测试代码如下: package ...
随机推荐
- hihoCoder 1187
今天BC爆0了....但是日子还是要过的....要回学校毕业了~~大学就这么“荒废”了. 这个是hihoCoder的1187,比较基础的一道题. 题目链接: http://hihocoder.com/ ...
- php的get_object_vars函数
我在看ecshop源码的时候,发现了一个非常有趣的函数,在此记下:get_object_vars() 从字面我们可以猜到,这个函数是针对类的一个方法:语法:array get_object_vars ...
- idea常用快捷键(转)
---恢复内容开始--- IntelliJ Idea 常用快捷键列表 Ctrl+Shift + Enter,语句完成 “!”,否定完成,输入表达式时按 “!”键 Ctrl+E,最近的文件 Ctrl+S ...
- Nginx报错-找不到路径
前言 最近在git bash里输入命令启动Nginx服务,总提示找不到路径,令我困惑不已 我反复检查安装路径和输入命令,确认无误 小技巧:复制路径可直接ctrl+c后在git ba ...
- golang 获取statuscode
最近日志打印的时候需要打印状态码,但是因为interface的原因直接获取失败,http.Request里面的response不知道怎么使用,所以就自己重写writeheader,write来截取st ...
- JS排序之快速排序
JS排序之快速排序 一个数组中的数据,选择索引为(2/数组长度)的那个数据作为基数,数组中的其他数据与它对比,比它数值小的放在做数组,比它数值大的放在右数组,最后组合 左数组+基数+右数组,其中,左数 ...
- 联想VIBE Shot(Z90-7/全网通) 解锁BootLoader
工具下载链接: http://pan.baidu.com/s/1dF7zGTb 备用下载链接: http://pan.baidu.com/s/1i4UHP4L 本篇教程教你如何傻瓜式解锁BootLoa ...
- 阶乘问题-----sum随变量改变而改变
- response.getWriter().write()乱码问题
前台代码: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> & ...
- jq 跨域请求
//使用getJSON <script type="text/javascript"> $(function () { $("#btn2").cli ...