防止页面报错,拦截错误跳转到失败页面

//拦截

 if ( logger.isDebugEnabled() ) {
          logger.debug(
              "<com.ibmmt.staffmanager.web.action.LoginAction.execute()登陆失败");
        }
        return (actionMapping.findForward("errorpage"));
      }

 

//struts中配置

 

    <forward name="errorpage" path="/adminsys/authmng/common/errorpage.jsp" />

 

 

//具体方法中

 

 public LoginPurviewVO login(String IP, String strStaffId, String strPassword) throws
      StaffManagerException
{
    LoginPurviewVO loginPurviewVo = new LoginPurviewVO();
    Staff staff = null;
    try {

      staff = getStaff(strStaffId);
      GetLogger().info(staff);
      if (null == staff) {
        this.writeAccessLog(strStaffId, IP, loginPurviewVo.getLoginTime(), -4);
        throw new StaffManagerException("系统中无[" + strStaffId +
                                        "]用户的登录信息,请检查你的用户名称是否正确!");
      }
      loginPurviewVo.setRoles(staff.getRolesList());
      Set funcSet = staff.getFunctions();
      System.out.println(funcSet.size()+"权限----");
      if (funcSet != null) {
        Hashtable funcs = loginPurviewVo.getFunctions();
        System.out.println(loginPurviewVo.getFunctions().size()+"权限-2222222---");
        for (Iterator iter = funcSet.iterator(); iter.hasNext(); ) {
          Object item = (Object) iter.next();
          Function func = (Function) item;
          GetLogger().debug("+++++++++++++++++++++FunctionName-->" +
                            func.getName() +
                            "++++++++++++++++++++++++++++++++++++++++++");
          String name = func.getName();
          System.out.println(loginPurviewVo.getFunctions().size()+"--fff--"+name);
          name = name == null ? "" : name;
         funcs.put(func.getId(), name);
        }
      }
      System.out.println(loginPurviewVo.getFunctions().size()+"权限-333333---");
      Hashtable staffAllFuncs = this.getStaffAllFuncs(strStaffId,
          loginPurviewVo.getRoles(),
          loginPurviewVo.getFunctions());
      System.out.println(staffAllFuncs.size()+"权限-1111---");
      loginPurviewVo.setStaffAllFuncs(staffAllFuncs);
      loginPurviewVo.setUserID(staff.getId());
      loginPurviewVo.setUserName(staff.getName());
      loginPurviewVo.setDepartmentID(staff.getDeptId());
    }
    catch (Exception ex) {
      GetLogger().error("查询用户发生异常:", ex);
      staff = null;
      this.writeAccessLog(strStaffId, IP, loginPurviewVo.getLoginTime(), 0);
      throw new StaffManagerException("查询用户发生异常");
    }
    if (null != staff) {
      if (staff.getStaffPass().equals(strPassword)) {
        if (LoginValidate(staff.getStatusFlag(), staff.getEffTime(),
                          staff.getExpTime())) {
          if (false &&
              (staff.getLoginFlag() != null && staff.getLoginFlag().equals("1")
               && staff.getLoginIp() != null &&
               staff.getLoginIp().length() > 0
               && !staff.getLoginIp().equals(IP))) {
            loginPurviewVo.setLoginErrorCode( -2);
            GetLogger().info("-----[" + staff.getId() + "]重复登录-----");
            String strHostID = staff.getLoginIp();
            staff = null;
            this.writeAccessLog(strStaffId, IP, loginPurviewVo.getLoginTime(),
                                -2);
            throw new StaffManagerException("重复登录![此工号已经在IP=" + strHostID +
                                            "机器登录]");
          }
          else {
            loginPurviewVo.setLoginErrorCode(1);
            loginPurviewVo.setIP(IP);
            staff.setLoginFlag("1");
            staff.setLoginIp(IP);
            //    updateStaffForLogin(staff);
            //  this.writeAccessLog(strStaffId, IP, loginPurviewVo.getLoginTime(), 1);
          }
        }
        else {
          loginPurviewVo.setLoginErrorCode( -3);
          GetLogger().info("[" + staff.getId() + "]你的工号已经失效.");
          staff = null;
          this.writeAccessLog(strStaffId, IP, loginPurviewVo.getLoginTime(), -3);
          throw new StaffManagerException("你的工号已经失效,不能登录,请和系统管理员联系。");
        }
      }
      else {
        loginPurviewVo.setLoginErrorCode( -1);
        GetLogger().info("[" + staff.getId() + "]密码不正确!");
        staff = null;
        this.writeAccessLog(strStaffId, IP, loginPurviewVo.getLoginTime(), -1);
        throw new StaffManagerException("密码不正确111!");
       
      }
    }
    GetLogger().debug("Login error code = " + loginPurviewVo.getLoginErrorCode());
    staff = null;
    return loginPurviewVo;
  }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值