package com.tfy.oa.action;
import javax.annotation.Resource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.tfy.oa.Util.OAUtils;
import com.tfy.oa.dao.LoginDao;
import com.tfy.oa.dao.UserDao;
import com.tfy.oa.dao.impl.UserDaoImpl;
import com.tfy.oa.domain.User;
import com.tfy.oa.service.LoginService;
import com.tfy.oa.service.UserService;
@SuppressWarnings("serial")
@Controller("loginAction")
@Scope("prototype")
public class LoginAction extends ActionSupport implements ModelDriven<User>{
@Resource(name="loginService")
private LoginService loginService;
private UserDao udao = (UserDaoImpl) new UserDaoImpl();
private User model=new User();//放到栈顶
private UserService userService;
// private String username;
// private String password;
public String login() {
System.out.println("LoginAction tfy home()");
// User u = userService.findUser(model);
System.out.println("this.getModel().getUsername()=="+this.getModel().getUsername());
System.out.println("this.getModel().getPassword())=="+this.getModel().getPassword());
User user=this.loginService.login(this.getModel().getUsername(),this.getModel().getPassword());
/*if (u != null) {
return SUCCESS;
}
return "input";*/
if(user==null){
//用户名和密码错误
//在登陆页面显示错误信息
return "input";
}else{
OAUtils.putUserToSession(user);
return "index";
}
}
public UserService getUserService() {
return userService;
}
public void setUserService(UserService userService) {
this.userService = userService;
}
/*
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 User getModel() {
return this.model;
}
}
import javax.annotation.Resource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.tfy.oa.Util.OAUtils;
import com.tfy.oa.dao.LoginDao;
import com.tfy.oa.dao.UserDao;
import com.tfy.oa.dao.impl.UserDaoImpl;
import com.tfy.oa.domain.User;
import com.tfy.oa.service.LoginService;
import com.tfy.oa.service.UserService;
@SuppressWarnings("serial")
@Controller("loginAction")
@Scope("prototype")
public class LoginAction extends ActionSupport implements ModelDriven<User>{
@Resource(name="loginService")
private LoginService loginService;
private UserDao udao = (UserDaoImpl) new UserDaoImpl();
private User model=new User();//放到栈顶
private UserService userService;
// private String username;
// private String password;
public String login() {
System.out.println("LoginAction tfy home()");
// User u = userService.findUser(model);
System.out.println("this.getModel().getUsername()=="+this.getModel().getUsername());
System.out.println("this.getModel().getPassword())=="+this.getModel().getPassword());
User user=this.loginService.login(this.getModel().getUsername(),this.getModel().getPassword());
/*if (u != null) {
return SUCCESS;
}
return "input";*/
if(user==null){
//用户名和密码错误
//在登陆页面显示错误信息
return "input";
}else{
OAUtils.putUserToSession(user);
return "index";
}
}
public UserService getUserService() {
return userService;
}
public void setUserService(UserService userService) {
this.userService = userService;
}
/*
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 User getModel() {
return this.model;
}
}