jsp登录页面中当用户错误登录三次以后,再登录就跳的别的页面。这个代码怎么写?

解决方案 »

  1.   

    在Session中持有一个错误登录次数计数器,第4次登录的时候,forward或redirect到别的页面。
    正确登录的时候,计数器清零或remove
      

  2.   

    在请求的jsp页面,或servlet,或action里,用session记录登录的次数,再判断 public ActionForward execute(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    {
    HttpSession session=request.getSession();

      boolean bool=你的登录方法();
      if(bool)
      return mapping.findForward("index");

      else
      {
      int i=1;
      if(session.getAttribute("count")!=null)
        i=Integer.parseInt(session.getAttribute("count").toString());
      if(i>3)
      return mapping.findForward("error");
      else
                           {
                              session.setAttribute("count",i)
      return mapping.findForward("login");
                            }
      }
    }