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 } }