Demo entry 6641045

卢广航

   

Submitted by 11 on Sep 15, 2017 at 06:33
Language: Java. Code size: 2.0 kB.

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
    throws IOException, ServletException
  {
    Map model = new HashMap();
    HttpServletResponse resp = (HttpServletResponse)response;
    HttpServletRequest req = (HttpServletRequest)request;
    String basePath = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort() + req.getContextPath() + "/";

    SessionManager sm = new SessionManager(req);
    Object user = sm.getValue("user");

    if (user == null)
    {
      String urlAction = req.getRequestURI();
      for (int i = 0; i < this.notRegUrl.length; ++i) {
        String notRegUrlItem = this.notRegUrl[i];
        if (urlAction.contains(notRegUrlItem)) {
          chain.doFilter(request, response);
          return;
        }
      }
      if ((req.getHeader("x-requested-with") != null) && (req.getHeader("x-requested-with").equalsIgnoreCase("XMLHttpRequest"))) {
        resp.addHeader("sessionstatus", "timeout");
      }
      else
      {
        resp.sendRedirect(basePath + "user.action?method=loginpage");
      }

    }
    else
    {
      if (!(StringUtils.isEmpty(request.getParameter("resId"))))
      {
        String resId = request.getParameter("resId");

        UserService userService = (UserService)SpringContextUtils.getBean("userServiceImpl");

        ResLog resLog = new ResLog();
        User u = (User)user;
        resLog.setLoginId(u.getUserAccount());
        resLog.setLoginIp(request.getRemoteAddr());
        resLog.setLoginTime(new Date());
        resLog.setUserId(u.getUserId());
        resLog.setSysId(Long.valueOf(103L));
        resLog.setResId(Long.valueOf(Long.parseLong(resId)));
        try {
          userService.addResLog(resLog);
        } catch (ServiceException e) {
          model.put("message", "系统异常," + e.getMessage());
        }
      }
      chain.doFilter(request, response);
    }
  }

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).