哪位童鞋知道在3.0版本用注解怎么配置noLoginPaths吗?
哪位童鞋知道在3.0版本用注解怎么配置noLoginPaths吗?
哪位童鞋知道在3.0版本用注解怎么配置noLoginPaths吗?
2018-03-26
过滤器并没有noLogginPaths这个参数, 要是想实现只能在过滤器的初始化时候设置上哪些不要过滤。下面是练习写的一个demo
@WebFilter(urlPatterns = { "*.jsp" },initParams ={@WebInitParam(name = "myNoLoginPaths", value = "/cc.jsp;/dd.jsp") })
public class MyFilter implements Filter {
private FilterConfig config;
@Override
public void destroy() {
}
@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) arg0;
//判断是否需要拦截
boolean needFilte = true;
//获取 不拦截的路径列表
String noLoginPaths = config.getInitParameter("myNoLoginPaths");
if(noLoginPaths!= null && !"".equals(noLoginPaths)){
String[] strings = noLoginPaths.split(";");
for (String tempUrl : strings) {
if(request.getRequestURI().indexOf(tempUrl)!=-1 ){
needFilte = false;
break;
}
}
}
if(needFilte){
//具体的拦截处理逻辑
System.out.println("过滤器处理业务"+request.getRequestURI());
}
arg2.doFilter(arg0, arg1);
}
@Override
public void init(FilterConfig arg0) throws ServletException {
config = arg0;
}
}
举报