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 ...
随机推荐
- Unity中内嵌网页插件UniWebView
一.常见Unity中内嵌网页实现方式: 1.UnityWebCore只支持windows 2.Unity-Webview支持Android,IOS 3.UniWebView支持mac os,Andro ...
- Windows7下caffe-ssd-microsoft下编译
整个编译可谓漫长 编译了两天 网上教程也很多 但是也很杂 遇到各种错误 总归是编完了 1.下载Windows版本的Caffe-SSD源码 下载链接:https://github.com/conner9 ...
- ACM_一道耗时间的水题
一道耗时间的水题 Time Limit: 2000/1000ms (Java/Others) Problem Description: Do you know how to read the phon ...
- C - Haiku
Problem description Haiku is a genre of Japanese traditional poetry. A haiku poem consists of 17 syl ...
- Asp.net三种事务处理
事务处理是在数据处理时经常遇到的问题,经常用到的方法有以下三种总结整理如下:方法1:直接写入到sql 中在存储过程中使用 BEGIN TRANS, COMMIT TRANS, ROLLBACK TRA ...
- C#比较两个日期的大小 .net
using System;using System.Collections; public class MyClass{public static void Main(){DateTime dt1 = ...
- [编码]ASCII、GBK、Unicode(万国码) 和 UTF-8
American ASCII编码 (American Standard Code for Information Interchange,美国信息互换标准代码) China gbk编码 ...
- logical vs physical address
Logical vs physical address 1) An address generated by the CPU is a logical address. Whereas, an ad ...
- MOOC推荐及三门基础学科
top1:学堂在线 http://www.xuetangx.com/ top2:网易云课堂 http://study.163.com/ top3:coursera https://www.course ...
- Docker 数据卷重复挂载测试
没想到一年没写博客了,这中间都是记在自己的笔记本上,大部分网上都有,这个好像没有,所以发上来吧! 本文是测试Docker容器(相同目录/父子目录)同时挂载到宿主机(同目录/不同目录)时的情况,废话少说 ...