Target: The Tomcat server provides an interface that cannot be accessed in other domains and requires an additional access-control-allow-origin:*
There are many methods of direct configuration, but I have not succeeded, so I can write the interceptor myself.
1. Writing Interceptor Code
Create a new class, implement the filter interface, the code is as follows
Package Com.itxc.filter;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 () { }}
2. Configure Web. xml
<filter> <filter-name>CorsFilter</filter-name> <filter-class> com.itxc.filter.corsfilter</filter-class> </filter> <filter-mapping> < filter-name>corsfilter</filter-name> <url-pattern>/*</url-pattern> </ Filter-mapping>
3. Remove the mess configuration you've previously configured for this feature.
It's done.
Tomcat adds the cross-domain access feature-access-control-allow-origin:*