package com.soft.filter;/** * Created by Administrator on 2017/2/6. */import javax.servlet.*;import javax.servlet.http.HttpServletResponse;import java.io.IOException;public class CORSFilter implements Filter { @Override public void init(FilterConfig filterConfig) throws ServletException { } @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletResponse httPResponse = (HttpServletResponse) servletResponse; httpResponse.addHeader("Access-Control-Allow-Origin", "*"); filterChain.doFilter(servletRequest, servletResponse); } @Override public void destroy() { }}
<filter> <filter-name>CorsFilter</filter-name> <filter-class>com.soft.filter.CORSFilter</filter-class></filter><filter-mapping> <filter-name>CorsFilter</filter-name> <url-pattern>/*</url-pattern></filter-mapping>文章转载于 http://www.cnblogs.com/joshualzb/p/5528205.html
新闻热点
疑难解答