第一种:一般类,带有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的方法的更多相关文章

  1. .Net MVC 导入导出Excel总结(三种导出Excel方法,一种导入Excel方法) 通过MVC控制器导出导入Excel文件(可用于java SSH架构)

    .Net MVC  导入导出Excel总结(三种导出Excel方法,一种导入Excel方法) [原文地址] 通过MVC控制器导出导入Excel文件(可用于java SSH架构)   public cl ...

  2. JSON三种数据解析方法(转)

    原 JSON三种数据解析方法 2018年01月15日 13:05:01 zhoujiang2012 阅读数:7896    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blo ...

  3. 同源策略(same-origin policy)及三种跨域方法

    同源策略(same-origin policy)及三种跨域方法 1.同源策略 含义: 同源是指文档的来源相同,主要包括三个方面 协议 主机 载入文档的URL端口 所以同源策略就是指脚本只能读取和所属文 ...

  4. 以用户名注册来分析三种Action获取数据的方式

    1.注入属性 直接注入属性: public String userName; public String getUserName() { return userName; } public void ...

  5. halcon三种模板匹配方法

    halcon有三种模板匹配方法:即Component-Based.Gray-Value-Based.Shaped_based,分别是基于组件(或成分.元素)的匹配,基于灰度值的匹配和基于形状的匹配,此 ...

  6. iOS——浅谈iOS中三种生成随机数方法

    ios 有如下三种随机数方法:

  7. Sencha 基础Demo测试,三种showView的方法

    直接贴代码吧 Ext.define("build.controller.MainController",{ extend:"Ext.app.Controller" ...

  8. Entity Framework关联实体的三种加载方法

    推荐文章 EF性能之关联加载 总结很好 一:介绍三种加载方式 Entity Framework作为一个优秀的ORM框架,它使得操作数据库就像操作内存中的数据一样,但是这种抽象是有性能代价的,故鱼和熊掌 ...

  9. List 三种遍历的方法

    学习java语言list遍历的三种方法,顺便测试各种遍历方法的性能,测试方法为在ArrayList中插入1千万条记录,然后遍历ArrayList,发现了一个奇怪的现象,测试代码如下: package ...

随机推荐

  1. codevs2800送外卖(floyd+状压dp)

    2800 送外卖  时间限制: 2 s  空间限制: 256000 KB  题目等级 : 钻石 Diamond     题目描述 Description 有一个送外卖的,他手上有n份订单,他要把n份东 ...

  2. Beta冲刺-星期三

    这个作业属于哪个课程  <课程的链接>            这个作业要求在哪里 <作业要求的链接> 团队名称 Three cobblers 这个作业的目标 剩余任务预估,分配 ...

  3. Gradle 自定义Task 打Jar包

    可以作为Jar包内容的有两个地方: : build/intermediates/bundles/release/ 下的classes.jar : build/intermediates/classes ...

  4. 【Hexo】deploy出错的解决方法

    .ERROR Deployer not found: git 执行npm install hexo-deployer-git --save .$ hexo d INFO Deploying: git ...

  5. 【sqli-labs】 less42 POST -Error based -String -Stacked(POST型基于错误的堆叠查询字符型注入)

    Forgot your password? New User click here? 看源码,可以发现和less 24不同的一点在于password字段没有进行转义处理 那就对password字段进行 ...

  6. 【WPS】表格使用VBA宏编程写入ini文件实现软件多语言

    前言:公司软件最近在做多语言版本,而又来一个西班牙文版本的,之前已经做过中文版本,英文版本和法文版本,之前是同事做的,现在安排我做,之前的做法,使用wps表格,翻译好,然后一个一个复制粘贴到ini文件 ...

  7. day001 Python 计算机基础(2019年5月16日)

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp作为一名程序员或者即将踏入IT行业的准程序员,学习任何一门编程语言,都需要有基本的计算机基础 ...

  8. select和epoll最大的区别

    先说说阻塞,因为一个线程只能处理一个套接字的I/O事件,如果想同时处理多个,可以利用非阻塞忙轮询的方式,伪代码如下: while true { for i in stream[] { if i has ...

  9. Ubuntu安装RTX2080显卡驱动

    安装RTX2080显卡驱动 近日新购了一台DELL服务器,用于TensorFlow,由于显卡是另加的,需要安装显卡驱动. 服务器配置 服务器型号:DELL PowerEdge R730 CPU:2*I ...

  10. 360 基于 Prometheus的在线服务监控实践

    转自:https://mp.weixin.qq.com/s/lcjZzjptxrUBN1999k_rXw 主题简介: Prometheus基础介绍 Prometheus打点及查询技巧 Promethe ...