Chinaunix首页 | 论坛 | 博客
  • 博客访问: 253156
  • 博文数量: 22
  • 博客积分: 2510
  • 博客等级: 少校
  • 技术积分: 518
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-13 12:03
文章分类

全部博文(22)

文章存档

2010年(1)

2009年(1)

2008年(20)

我的朋友

分类: Java

2008-11-21 10:23:05

package com.snsoft.tutorial.action;

 

import com.opensymphony.xwork2.ActionSupport;

import com.snsoft.tutorial.dao.IUserDAO;

import com.snsoft.tutorial.domain.TUser;

 

public class LoginAction extends ActionSupport {

    private static final long serialVersionUID = 2772939669445960595L;

   

    private String username;

   

    private String password;

   

    private String message;

   

    private IUserDAO userDao=null;

   

    /**

     * 登录方法

     * @return

     */

    public String login(){

      

       if(this.username!=null && this.password!=null){

           TUser user=this.userDao.getUserByName(this.username);

           if(user!=null){

              if(this.password.equals(user.getPassword())){

                  return "success";              

              }else{

                  this.message="登录密码错误!";

              }

           }else{

              this.message="不存在该登录用户!";

           }         

       }else{

           this.message="用户名和密码不能为空值!";

       }

      

       return "error";

    }

 

    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;

    }

 

    public String getMessage() {

       return message;

    }

 

    public void setMessage(String message) {

       this.message = message;

    }

 

    public IUserDAO getUserDao() {

       return userDao;

    }

 

    public void setUserDao(IUserDAO userDao) {

       this.userDao = userDao;

    }

   

}

 

package com.snsoft.tutorial.action;

 

import com.opensymphony.xwork2.ActionSupport;

import com.snsoft.tutorial.dao.IUserDAO;

import com.snsoft.tutorial.domain.TUser;

 

import java.util.List;

 

public class RegisterAction extends ActionSupport {

 

    private static final long serialVersionUID = 4120794399269317310L;

   

    private String id;

   

    private String username;

   

    private String password;

   

    private String emaillist;

   

    private String message; 

   

    @SuppressWarnings("unchecked")

    private List users;

   

    private IUserDAO userDao=null;

      

    /**

     * 注册新用户

     * @return

     */

    public String register(){

      

       if(this.username==null){

           this.message="用户名不能为空值!";   

           return "error";

       }

      

       if(this.password==null){

           this.message="登录密码不能设置为空值!";

           return "error";

       }

      

       if(this.emaillist==null){

           this.message="邮件地址不能为空值!";

           return "error";

       }

      

       TUser user=new TUser();

       user.setUsername(this.username);

       user.setPassword(this.password);

       user.setEmaillist(this.emaillist);

      

       this.userDao.addUser(user);

      

       return "success";

    }

   

    /**

     * 显示用户列表

     * @return

     */

    public String list(){

       this.users=this.userDao.getUsers();

       return "success";

    }

   

    public String delete(){

       return "success";

    }

   

    public String update(){

       return "success";

    }

    public String getId() {

       return id;

    }

    public void setId(String id) {

       this.id = id;

    }

    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;

    }

    public String getEmaillist() {

       return emaillist;

    }

    public void setEmaillist(String emaillist) {

       this.emaillist = emaillist;

    }

    public String getMessage() {

       return message;

    }

    public void setMessage(String message) {

       this.message = message;

    }

    @SuppressWarnings("unchecked")

    public List getUsers() {

       return users;

    }

    @SuppressWarnings("unchecked")

    public void setUsers(List users) {

       this.users = users;

    }

    public IUserDAO getUserDao() {

       return userDao;

    }

    public void setUserDao(IUserDAO userDao) {

       this.userDao = userDao;

    }

   

}

阅读(2020) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2009-03-06 10:33:10

格式真规范!!!

ythtytht2009-01-14 23:11:49

教程不完整,JSP文件呢?