zoukankan      html  css  js  c++  java
  • 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。

  • 相关阅读:
    Solidworks如何设置零件材料,如何评估零件质量
    Office 如何双面打印Word文档
    Discuz常见小问题2-如何在新建的页面上只显示一部分板块
    Discuz常见小问题2-如何在数据库搜索指定关键字
    Discuz常见小问题2-如何修改整个网站的默认字体为微软雅黑
    Discuz常见小问题2-如何修改管理员密码,修改admin账户密码
    php使用include报错require_once(../include.php): failed to open stream: No such file or directo
    PHP中的__get()和__set()方法获取设置私有属性
    php->是什么意思
    PHP中require(),include(),require_once()和include_once()有什么区别
  • 原文地址:https://www.cnblogs.com/yfceshi/p/6918201.html
Copyright © 2011-2022 走看看