当前位置 : 主页 > 编程语言 > java >

域名过滤器

来源:互联网 收集:自由互联 发布时间:2021-06-28
域名过滤器 package org.woke.filter;import lombok.extern.slf4j.Slf4j;import javax.servlet.*;import javax.servlet.http.HttpServletResponse;import java.io.IOException;@Slf4jpublic class DomainFilter implements Filter { public void init(Fi
域名过滤器
package org.woke.filter;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Slf4j
public class DomainFilter implements Filter {

    public void init(FilterConfig filterConfig) throws ServletException {
     log.info("域名过滤器初始化");
    }

    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
        response.setHeader("Access-Control-Max-Age", "3600");
        response.addHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
        chain.doFilter(servletRequest, servletResponse);
    }

    public void destroy() {

    }
}
web.xml
 
    
  
   domainFilter
  
    
  
   org.woke.filter.DomainFilter
  
  
 
  
 
    
  
   domainFilter
  
    
  
   /*
  
  
 
网友评论