XMLHttpRequest cannot load http://130.51.23.12 : 8180/remotelogin. Preflight response is not successful. Add annotation to solve the problem: @ crossorigin (origins = "*", maxage = 3600)
This annotation comes after spring 4.2
If it is lower than version 4.2, add filter:
import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class CorsFilter implements Filter {
public void init(FilterConfig filterConfig) throws ServletException {}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
httpServletResponse.setHeader("Access-Control-Allow-Origin", "*");
httpServletResponse.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
httpServletResponse.setHeader("Access-Control-Max-Age", "3600");
httpServletResponse.setHeader("Access-Control-Allow-Headers",
"Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With, Access-Control-Allow-Methods, Access-Control-Allow-Origin");
httpServletResponse.setHeader("Access-Control-Allow-Credentials", "true");// 允许cookie
chain.doFilter(request, response);
}
public void destroy() {}
}
web.xml
<filter>
<filter-name>corsFilter</filter-name>
<filter-class>com.x.sso.cas.server.security.CorsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>corsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Similar Posts:
- Spring MVC: How to Solve Chinese garbled code Issue
- Tomcat set x-frame-option
- Struts 2.0 Error: The Struts dispatcher cannot be found (Error 500 Internal Server Error)
- Configure Struts2 web.xml to report an error [How to Solve]
- [Solved] interceptor Cross-Domain Access-Control-Allow-Origin Error
- Resource interpreted as Stylesheet but transferred with MIME type text/html: css not work
- [Solved] Dubbo uses filter error: No such extension consumerStaticFilter for filter/com.alibaba.dubbo.rpc.Filter
- Web project management web.xml Listener monitoring summary
- How to Use awk to Analyze Nginx Log
- [Solved] Python import pandastime Error: Could not import the lzma module