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

小弟新手,struts+hibernate弄个登陆的问题,求解
自己随便练习一下

public   class   LoginAction   extends   Action   {
/*
  *   Generated   Methods
  */

/**  
  *   Method   execute
  *   @param   mapping
  *   @param   form
  *   @param   request
  *   @param   response
  *   @return   ActionForward
  */
public   ActionForward   execute(ActionMapping   mapping,   ActionForm   form,
HttpServletRequest   request,   HttpServletResponse   response)   {
LoginForm   loginForm   =   (LoginForm)   form;//   TODO   Auto-generated   method   stub
if   (isCancelled(request)){
return   mapping.findForward( "register ");
}
RegisterDao   dao   =   new   RegisterDao();
List   list=dao.showList();
request.setAttribute( "list ",list);
for   (Object   n:list){
UserInfo   user   =   (UserInfo)n;
if(loginForm.getUserName()==user.getName()   &&   loginForm.getPassword()==user.getPassword()){
return   mapping.findForward( "success ");}
else   {return   mapping.findForward( "fail ");}
}
return   null;
}
}
下面   这个是   showlist的方法:
public   List   showList()   {
DetachedCriteria   detachedCriteria   =   DetachedCriteria
.forClass(UserInfo.class);
session   =   SessionFactory.getSession();
List   list   =   (List)   detachedCriteria.getExecutableCriteria(session).list();
return   list;
}

不管怎样都是返回的fail,不知道怎么办了,求高手解答

------解决方案--------------------
条件判断改成以下:
loginForm.getUserName().equels(user.getName()) &&
loginForm.getPassword().equels(user.getPassword())
”==“判断两个参数的地址是都相等
equels()判断地址指向的值是否相等
------解决方案--------------------
字符串比较要使用equals,
基本类型的比较使用 "== "