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 ...
随机推荐
- Check the difficulty of problems(概率+DP)
http://poj.org/problem?id=2151 看的题解..表示没看懂状态转移方程.. #include<stdio.h> #include<string.h> ...
- hihoCoder 1033
题目链接: http://hihocoder.com/problemset/problem/1033 听说这个题是xiaodao出的~~ 我们要知道dp其实就是一个记忆化搜索的过程,如果某个子结构之前 ...
- Java NIO Buffer说明
Buffer 有3个重要的参数:位置(position).容量(capactiy).上限(limit) 位置(position): 写:当前缓冲区的位置,将从position的下一个位置写数据. 读: ...
- POJ 1753 DFS
思路: 有过两个裸搜的思路,第一个一个无限TLE,第二个还不慢... 错误思路:迭代加深搜索,枚举翻第几个棋,挂的原因:16的16次方,不挂就怪了. 错误代码见下: #include <cstd ...
- java热部署
最近使用java做项目,研究了一下热部署,能够提高工作效率. 需要准备的工具: 1.安装文件http://update.zeroturnaround.com/update-site/ 2.破解 下载破 ...
- sql 改字段名
sp_rename '[zErpMini].[dbo].[STK_Stock].Isextension','IsExtened'
- SQL Server2008优化之SET STATISTICS开关
一.准备工作 缓存对于某个查询的性能影响十分之大,所以优化之前要清空缓存. 清除Buffer Pool时面的所有缓存 DBCC DROPCLEANBUFFERS清除Buffer Pool里的所有缓存的 ...
- Assembly之instruction之CMP
CMP[.W] Compare source and destinationCMP.B Compare source and destination Syntax CMP src,dst or ...
- PCL: 根据几何规则的曲面剖分-贪婪法表面重建三角网格
点云场景中进行物体识别,使用全局特征的方法严重依赖于点云分割,难以适应杂乱场景.使用局部特征,即对点云进行提取类似于3D SURF.ROPS之类的局部特征,需要寻找离散点云块的局部显著性. 点云的基本 ...
- MVC POST请求后执行javascript代码
[HttpPost] public ActionResult PostTest() { //你的业务代码 //...... //要执行的js string js = "window.loca ...