1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
| package info.xiaomo.core.filter;
import org.springframework.stereotype.Component;
import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* 把今天最好的表现当作明天最新的起点..~
* いま 最高の表現 として 明日最新の始発..~
* Today the best performance as tomorrow newest starter!
* Created by IntelliJ IDEA.
*
* @author: xiaomo
* @github: https://github.com/houko
* @email: hupengbest@163.com
* @QQ_NO: 83387856
* @Date: 2016/4/1516:25
* @Description:
* @Copyright(©) 2015 by xiaomo.
**/
@Component
public class CORSFilter implements Filter {
/**
* 初始化
*
* @param filterConfig filterConfig
* @throws ServletException ServletException
*/
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
/**
* CORS 过滤器
*
* @param req rq
* @param res res
* @param chain chin
* @throws IOException IOException
* @throws ServletException ServletException
*/
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletResponse response = (HttpServletResponse) res;
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers, If-Modified-Since");
chain.doFilter(req, res);
}
/**
* 销毁对象
*/
public void destroy() {
}
}
|