Example #1
0
 /**
  * @param request ServletRequest
  * @param res ServletResponse
  * @param chain FilterChain
  * @throws IOException
  * @throws ServletException
  */
 public void doFilter(ServletRequest request, ServletResponse res, FilterChain chain)
     throws IOException, ServletException {
   try {
     HttpServletRequest req = (HttpServletRequest) request;
     if (isStartLog && !req.getRemoteAddr().equals("127.0.0.1")) {
       SfUserDTO userAccount = (SfUserDTO) SessionUtil.getUserAccount(req);
       String reqUrl = req.getRequestURI();
       if (userAccount != null) {
         if (reqUrl.indexOf(".jsp") > -1 || reqUrl.indexOf("/servlet") > -1) {
           String action = "查询";
           String queryStr = req.getQueryString();
           String[] paras = StrUtil.splitStr(queryStr, "&");
           if (paras != null && paras.length > 0) {
             int index = -1;
             String singlePara = "";
             String paraName = "";
             for (int i = 0; i < paras.length; i++) {
               singlePara = paras[i];
               if (singlePara == null) {
                 continue;
               }
               index = singlePara.indexOf("=");
               if (index != -1) {
                 paraName = singlePara.substring(0, index);
                 if (paraName.equals("act")) {
                   action = singlePara.substring(index + 1);
                   break;
                 }
               }
             }
           }
           if (!StrUtil.isEmpty(queryStr)) {
             reqUrl = reqUrl + "?" + queryStr;
           }
           FilterConfigDTO filterConfigDTO = SessionUtil.getFilterConfigDTO(req);
           if (reqUrl.equals(filterConfigDTO.getLoginSuccessURL())) {
             action = "登录";
           }
           if (reqUrl.equals(filterConfigDTO.getLogOutServlet())) {
             action = "注销";
           }
           SfUserLogDTO logData = new SfUserLogDTO();
           logData.setUserId(userAccount.getUserId());
           logData.setUserAccount(userAccount.getLoginName());
           logData.setActionType(action);
           logData.setClientIp(req.getRemoteAddr());
           logData.setReqUrl(reqUrl);
           logData.setServer(req.getServerName());
           logData.setLogTime(CalendarUtil.getCurrCalendar());
           logData(userAccount, logData);
         }
       }
     }
     if (chain != null) {
       chain.doFilter(req, res);
     }
   } catch (DataHandleException ex) {
     ex.printLog();
     throw new ServletException(ex);
   } catch (CalendarException ex) {
     ex.printLog();
     throw new ServletException(ex);
   }
 }