1 public class AllowOriginFilter implements Filter {
2
3 @SuppressWarnings("unused")
4 public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
5
6 HttpServletResponse response = (HttpServletResponse) res;
7 HttpServletRequest request=(HttpServletRequest)req;
8 response.setHeader("Access-Control-Allow-Origin", "*"); // 设置允许所有跨域访问 9 response.setHeader("Access-Control-Allow-Methods", "POST,GET,PUT,OPTIONS,DELETE");
10 response.setHeader("Access-Control-Max-Age", "3600");
11 response.setHeader("Access-Control-Allow-Headers", "Origin,X-Requested-With,Content-Type,Accept,Authorization,token");
12 response.setHeader("Access-Control-Allow-Credentials", "true");
13 chain.doFilter(req,res);
14 }
15
16 public void init(FilterConfig filterConfig) {}
17
18 public void destroy() {}
19
20
21 }