|
发表于 2020-3-23 14:30:02
|
显示全部楼层
filter可以配置参数,
你可以配置一个参数叫exclusion,中间用逗号隔开,记录在里面的路径,虽然进入了filter,但是不做处理
比如
<filter>
.....
<init-param>
<param-name>exclusions</param-name>
<param-value>/, /index.jsp, /login.do, /logout.do, /test.jsp</param-value>
</init-param>
</filter>
filter
public class MyFilter implements Filter {
Set exclusions;
public void init(FilterConfig filterConfig) throws ServletException {
super.init(filterConfig);
String exclu = filterConfig.getInitParameter("exclusions");
exclusions = new HashSet();
// split operations
}
public void doFilter(ServletRequest request,
ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
if (!exclusions.contains(httpRequest.getServletPath())) {
// 原来的操作
}
} |
|