分类: 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;
}
}