//dao注入
private static String hqlname = "from User u where u.name=?";
private static String hqlpassword = "from User u where u.password=?";
public boolean isValidUser(String one,int i){
List userList;
if(i==0){
userList=this.getHibernateTemplate().find(hqlname+"",one);
}else{
userList=this.getHibernateTemplate().find(hqlpassword+"",one);
}
if (userList.size() > 0) {
return true;
}
return false;
}
//action
if(userDao.isValidUser(name, password)){
//return mapping.findForward("welcome");
return new ActionForward("/pages/welcome.jsp");
}else{
ActionMessages message = new ActionMessages();
if(userDao.isValidUser(name,0)){
}else{
message.add("name",new ActionMessage("name.error",true));
}
if(userDao.isValidUser(password,1)){
}else{
message.add("password",new ActionMessage("password.error",true));
}
this.saveErrors(request,message);
//return new ActionForward("/pages/login.jsp");
return mapping.findForward("welcome");
}