package web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.IloginRed;
import model.Login;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
public class LoginController extends SimpleFormController {
private IloginRed iloginred;
public LoginController() {
this.setCommandClass(LoginForm.class);
}
protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object command,
BindException exception) throws Exception {
request.setCharacterEncoding("utf-8");
LoginForm login = (LoginForm) command;
Login form = new Login();
form.setUsername(login.getUsername());
form.setPassword(login.getPasswd());
Login user = iloginred.findByName(form.getUsername());
if (user == null) {
exception.rejectValue("username", "no_such_user", "查无此人");
return new ModelAndView(this.getFormView(), exception.getModel());
} else if (user != null
&& !user.getPassword().equals(form.getPassword())) {
exception.rejectValue("passwd", "wrong_passwd", "密码错误");
return new ModelAndView(this.getFormView(), exception.getModel());
} else {
System.out.println(iloginred.findall());
request.getSession()
.setAttribute("valid_user", iloginred.findall());
return new ModelAndView(this.getSuccessView());
}
}
public IloginRed getIloginred() {
return iloginred;
}
public void setIloginred(IloginRed iloginred) {
this.iloginred = iloginred;
}
}
评论14
最新资源