当前位置: 代码迷 >> Java Web开发 >> 如何老是跳转request.setAttribute("msg" "用户名或密码错误,登录失败。");并且跳转到index.jsp,如何不跳啊,
  详细解决方案

如何老是跳转request.setAttribute("msg" "用户名或密码错误,登录失败。");并且跳转到index.jsp,如何不跳啊,

热度:825   发布时间:2016-04-17 00:55:02.0
怎么老是跳转request.setAttribute("msg", "用户名或密码错误,登录失败。");,,,,,,并且跳转到index.jsp,怎么不跳啊,急
public ActionForward doLogin(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws SQLException, IOException, ServletException {
// TODO Auto-generated method stub

request.getSession().removeAttribute("user");

String userName=request.getParameter("userName");
String userPwd=request.getParameter("userPwd");
User user=userBiz.login(userName,userPwd);
if(null!=user && user.getUserStatus()!=UserBiz.user_status_forbid)//登录成功
{
request.getSession().setAttribute("user", user);
if(user.getUserStatus()==UserBiz.user_status_admin)
{
//response.sendRedirect("admin.jsp");
//request.getRequestDispatcher("admin.jsp).forward(request, response);
//response.getWriter().println("<script language='javascript'>window.location.replace('admin.jsp');</script>");
return mapping.findForward("admin");
}else if(user.getUserStatus()==UserBiz.user_status_normal)
{
//response.sendRedirect("index.jsp");
return mapping.findForward("index");
}
}else
{
request.setAttribute("msg", "用户名或密码错误,登录失败。");
return mapping.findForward("index");
}
return null;
}

------解决方案--------------------
if(null!=user && user.getUserStatus()!=UserBiz.user_status_forbid)//登录成功

这一句不成立,解决办法:
在他之前用
System.out.println(user);
System.out.println(user.getUserStatus());
看看是不是空,如果是空的话说明没收到数据,jsp页面估计有问题。自己试试吧
  相关解决方案