使用filter实现跨域

开发项目过程中遇到了跨域问题,发现使用filter在web.xml中可以解决
有一个可用的CORSFilter,不用自定义了


    CORS
    com.thetransactioncompany.cors.CORSFilter
    
      cors.allowOrigin
      *
    
    
      cors.supportedMethods
      GET, POST, HEAD, PUT, DELETE,OPTIONS
    
  

代码具体实现

取到ServletContextHandler对象context,
然后

context.addFilter(CORSFilter.class,"/*", EnumSet.of(DispatcherType.REQUEST));

即可

你可能感兴趣的:(使用filter实现跨域)