Filter解決ajax跨域問題
阿新 • • 發佈:2017-12-06
-a json ces all -m ons main charset -h
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跨域問題