Filter解决ajax跨域问题
Posted 闲杂人等
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Filter解决ajax跨域问题相关的知识,希望对你有一定的参考价值。
public class CrossDomainFilter implements Filter { @Override public void init(FilterConfig filterConfig) throws ServletException { // TODO Auto-generated method stub } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletResponse resp = (HttpServletResponse) response; // 允许跨域ajax请求 resp.setHeader("Access-Control-Allow-Origin", "*"); resp.setHeader("Access-Control-Allow-Methods", "*"); resp.setHeader("Access-Control-Allow-Headers", "accept, origin, content-type"); resp.setHeader("Content-Type", "application/json;charset=UTF-8"); chain.doFilter(request, resp); } @Override public void destroy() { // TODO Auto-generated method stub } }
以上是关于Filter解决ajax跨域问题的主要内容,如果未能解决你的问题,请参考以下文章