2.package com.qmsk.crm.sys.filter;
import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import com.qmsk.crm.util.Constant; import com.qmsk.crm.util.KouYangUtil; import com.qmsk.crm.xitongguanli.po.Path; import com.qmsk.crm.xitongguanli.po.RenYuan; import com.qmsk.crm.xitongguanli.po.RiZhi; import com.qmsk.crm.xitongguanli.service.IPathService; import com.qmsk.crm.xitongguanli.service.IRiZhiService; public class QXFilter implements Filter { @Override public void destroy() { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest request2 = (HttpServletRequest) request; String link = request2.getServletPath(); if(!link.endsWith(".jsp") && (!link.endsWith(".action"))){ chain.doFilter(request, response); } else if((link.endsWith(".jsp") && "/index.jsp".equals(link)) || (link.endsWith(".jsp") && "/yzm.jsp".equals(link)) || (link.endsWith(".jsp") && "/login.jsp".equals(link)) || (link.endsWith(".action") && ("/Login.action".equals(link) || "/TuiChu.action".equals(link)))){ chain.doFilter(request, response); } else { HttpSession session = request2.getSession(); RenYuan renYuan = (RenYuan) session.getAttribute(Constant.RENYUAN); if(renYuan != null){ //插入日志 IPathService pathService = (IPathService) KouYangUtil.getObjectService("PathService"); Path path = pathService.getPathByLink(link.substring(1)); if(path != null){ IRiZhiService riZhiService = (IRiZhiService) KouYangUtil.getObjectService("RiZhiService"); RiZhi riZhi = new RiZhi(); riZhi.setLink(path.getLink()); riZhi.setName(path.getName()); riZhi.setDescription(path.getDescription()); riZhi.setCaoZuoRYId(renYuan.getRenYuanId()); riZhi.setCaoZuoRYMC(renYuan.getName()); riZhiService.saveRiZhi(riZhi); } chain.doFilter(request, response); }else{ //request.getRequestDispatcher("/Forbidden.jsp").forward(request, response); request.getRequestDispatcher("/login.jsp").forward(request, response); } } } @Override public void init(FilterConfig filterConfig) throws ServletException { } }