Druid filter过滤请求
来源:互联网 发布:中传在线 网络教育 编辑:程序博客网 时间:2024/06/08 06:52
- web.xml配置
<filter> <filter-name>sessionFilter</filter-name> <filter-class>SessionFilter</filter-class> <init-param> <param-name>exclusions</param-name> <param-value>/login*</param-value> </init-param> </filter> <filter-mapping> <filter-name>sessionFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
- java代码
private Set<String> excludesPattern; protected PatternMatcher pathMatcher = new ServletPathMatcher(); public static final String PARAM_NAME_EXCLUSIONS = "exclusions"; public static String contextPath = ""; @Override public void destroy() { } @Override public void doFilter(ServletRequest request, ServletResponse response,FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpSession session = httpRequest.getSession(); String url = httpRequest.getRequestURI(); if (isExclusion(url)|) { chain.doFilter(request, response); return; } } @Override public void init(FilterConfig config) throws ServletException { //读取web.xml配置的不需要进行拦截的请求 String exclusions = config.getInitParameter(PARAM_NAME_EXCLUSIONS); if (exclusions != null && exclusions.trim().length() != 0) { excludesPattern = new HashSet<String>(Arrays.asList(exclusions.split("\\s*,\\s*"))); } getContextPath(config.getServletContext()); logger.info(contextPath); } //拦截过滤 public boolean isExclusion(String requestURI) { if (excludesPattern == null) { return false; } if(requestURI.equals(contextPath)){ return true; } if (contextPath != null && requestURI.startsWith(contextPath)) { requestURI = requestURI.substring(contextPath.length()); if (!requestURI.startsWith("/")) { requestURI = "/" + requestURI; } } for (String pattern : excludesPattern) { if (pathMatcher.matches(pattern, requestURI)) { return true; } } return false; } //获取根路径 public void getContextPath(ServletContext context) { if (context.getMajorVersion() == 2 && context.getMinorVersion() < 5) { return; } try { String path = context.getContextPath(); if (path == null || path.length() == 0) { path = "/"; } contextPath = path; } catch (NoSuchMethodError error) { error.printStackTrace(); } }
阅读全文
0 0
- Druid filter过滤请求
- 使用filter过滤请求
- 使用filter过滤请求
- 使用filter过滤请求
- Filter过滤器 过滤请求
- SpringBoot设置Filter过滤请求参数
- druid Filter 配置WebStatFilter
- filter实现过滤压缩指定的请求的操作
- struts2为什么filter不能过滤.action的请求
- Servlet中使用Filter来过滤请求编码
- Servlet原生Filter过滤非登录页面请求
- Filter过滤器的使用,实现在规定时间内过滤请求
- filter过滤
- filter过滤
- filter过滤、servlet过滤
- 使用struts2时,filter过滤器只过滤jsp文件不过滤action请求
- Filter过滤器只过滤jsp不过滤action请求的解决方案
- 使用struts2时,filter过滤器只过滤jsp文件不过滤action请求 .
- iOS占位文字placeholder设置技巧
- Unity移动物体到鼠标点击位置
- ACM 1005. 数独
- TrickGCD----筛法/分块/莫比乌斯函数
- com.google.gson.internal.LinkedTreeMap cannot be cast to entity
- Druid filter过滤请求
- raknet 发送数据时
- 查找二叉树最大值节点
- javascript中var that=this
- tomcat部署java项目之后,war可以删除吗?
- Spring技术内幕——深入解析Spring架构与设计原理(一)IOC实现原理
- Linux基础命令学习
- rhel7.2软件安装及yum源配置
- match(枚举)