www.pudn.com > liberSystem.rar > LoginAction.java, change:2012-06-06,size:1436b


package com.ccl.action; 
 
import javax.servlet.http.HttpSession; 
 
import org.apache.struts2.ServletActionContext; 
 
import com.ccl.service.LoginService; 
import com.opensymphony.xwork2.ActionSupport; 
 
public class LoginAction extends ActionSupport { 
	 
	private String username; 
	private String password; 
	private LoginService loginService=new LoginService();  
	/** 
	 *  
	 */ 
	private static final long serialVersionUID = 1L; 
 
	@Override 
	public String execute() throws Exception { 
		boolean flag=loginService.validateAdminLogin(username, password); 
		if(flag) 
		{ 
			HttpSession session= ServletActionContext.getRequest().getSession(); 
			session.setAttribute("user",loginService.getAdminLogin(username) ); 
			return SUCCESS; 
		}else{ 
			this.addFieldError("msg", "用户名或者密码错误"); 
			return INPUT; 
		} 
	} 
	 
	@Override 
	public void validate() { 
		if(this.username==null||this.username.trim().equals("")) 
		{ 
			this.addFieldError("username", "用户名不能为空"); 
		} 
		if(this.password==null||this.password.trim().equals("")) 
		{ 
			this.addFieldError("password", "用户名不能为空"); 
		} 
	} 
 
	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; 
	} 
}