美文网首页
Java简单CROSFilter支持跨域

Java简单CROSFilter支持跨域

作者: __KCN | 来源:发表于2018-05-03 11:54 被阅读0次
    @WebFilter(filterName="CROSFilter", urlPatterns = {"/*"})
    public class CROSFilter implements Filter {
    
        @Override
        public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
                throws IOException, ServletException {
            HttpServletResponse httpResponse = (HttpServletResponse)res;
            httpResponse.setHeader("Access-Control-Allow-Origin", "*");
            httpResponse.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
            httpResponse.setHeader("Access-Control-Max-Age", "1800");
            httpResponse.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
            httpResponse.setHeader("Access-Control-Allow-Credentials", "true");
            chain.doFilter(req, httpResponse);  
        }
    }
    
    

    相关文章

      网友评论

          本文标题:Java简单CROSFilter支持跨域

          本文链接:https://www.haomeiwen.com/subject/xsukrftx.html