action裡邊的登錄方法

public class AdminAction extends BaseAction {

// 當前Action涉及到業務對象
private AdminService adminService;

private Admin admin;

public void setAdminService(AdminService adminService) {
this.adminService = adminService;
}

public Admin getAdmin() {
return admin;
}

public void setAdmin(Admin admin) {
this.admin = admin;
}

public String login() {
System.out.println("login………………" + admin.getName() + "—"
+ admin.getPass());
if (ServletActionContext.getRequest().getSession()
.getAttribute("logadmin") != null) {
return "loginIn";
}
if (admin == null) {
return "loginOut";
}
admin = adminService.login(admin.getName(), admin.getPass());
System.out.println(admin);
// System.out.println(admin + "======");
ServletActionContext.getRequest().getSession()
.setAttribute("logadmin", admin);
return "loginIn";

}

public String logout() {

if (ServletActionContext.getRequest().getSession()
.getAttribute("logadmin") != null) {
ServletActionContext.getRequest().getSession()
.removeAttribute("logadmin");
}

return "loginOut";

You May Also Like