日期:2014-05-18  浏览次数:20608 次

Hibernate 异常
为什么下面的程序会抛出异常:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
LoginForm LoginForm = (LoginForm) form;
ActionMessages errors=new ActionMessages();
ActionForward forward=mapping.findForward("frontPage");
try{
Session dbSession=HibernateSessionFactory.getCurrentSession();
HttpSession session=request.getSession();
String hqlStr="from Userinfo as u where u.username=:username and u.pwd=:pwd";
Query query=dbSession.createQuery(hqlStr);
query.setString("username",LoginForm.getUsername());
query.setString("pwd",LoginForm.getPassword());

List result=query.list();
if(result.size()==0){
errors.add("inputErrors",new ActionMessage("index.loginError"));
this.saveMessages(request,errors);
forward=mapping.findForward("failed");
}else{
Userinfo user=(Userinfo) result.get(0);
session.setAttribute("user",user);
if(user.getPower()==1){
session.setAttribute("admin",true);
}
}
}catch(Exception e){
errors.add("dbError",new ActionMessage("globle.dbError"));
this.saveMessages(request,errors);
forward=mapping.findForward("errorPage");
}
return forward;
}
}

------解决方案--------------------
吧你的错误信息放上来