tip:在过滤器中解决跨域问题
一:java 代码实现跨域问题
HttpServletResponse httpResponse = (HttpServletResponse)servletResponse;
httpResponse.setHeader("Access-Control-Allow-Headers","Origin, X-Requested-With, Content-Type, Accept");
httpResponse.setHeader("Access-Control-Allow-Credentials", "true");
//匹配这个地址
httpResponse.addHeader("Access-Control-Allow-Origin", "http://127.0.0.1:8020");
//匹配所有
//response.setHeader("Access-Control-Allow-Origin", "*");
filterChain.doFilter(servletRequest, httpResponse);
二:nginx解决网站跨域问题
server {
listen 80;
server_name www.zyhome.com;
location /A {
proxy_pass http://a.a.com:81/A;
index index.html index.htm;
}
location /B {
proxy_pass http://b.b.com:81/B;
index index.html index.htm;
}
}