1.理解跨域问题:
2.如何解决:
http://blog.csdn.net/zhang6622056/article/details/75570518
https://blog.csdn.net/zhang6622056/article/details/75221492
跨域问题实战:
需要改动三个地方:
1对应代码:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency>
2.对应代码:
<!-- 2019-04-26 解决跨域问题 -->
<filter>
<filter-name>crossFilter</filter-name>
<filter-class>com.crup.political.filter.CorsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>crossFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
3对应代码:
/**
* 解决跨域
*/
public class CorsFilterimplements Filter {
@Override
public void destroy() {
// TODO Auto-generated method stub
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
httpServletResponse.setHeader("Access-Control-Allow-Origin", "*");
httpServletResponse.setHeader("Access-Control-Allow-Headers", "accept,content-type");
httpServletResponse.setHeader("Access-Control-Allow-Methods", "OPTIONS,GET,POST,DELETE,PUT");
chain.doFilter(request, httpServletResponse);
}
@Override
public void init(FilterConfig arg0)throws ServletException {
// TODO Auto-generated method stub
}
}