跨域问题解决方案
- 下载jar
cors-filter-2.9.jar
java-property-utils-1.13.jar
- 项目中web.xml 中添加filter,以及出现OPTIONS 类型的请求并返回403的解决方案
<filter>
<filter-name>CORS</filter-name>
<filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
<init-param>
<param-name>cors.allowOrigin</param-name>
<param-value>http://192.168.0.7:8077,http://192.168.0.8:8080,http://localhost:8188</param-value>
</init-param>
<init-param>
<param-name>cors.supportedMethods</param-name>
<param-value>GET, POST, OPTIONS, HEAD, PUT, DELETE</param-value>
</init-param>
<init-param>
<param-name>cors.supportedHeaders</param-name>
<param-value>Accept,Authorization, Origin, X-Requested-With, Content-Type, Last-Modified,token</param-value>
</init-param>
<init-param>
<param-name>cors.exposedHeaders</param-name>
<param-value>Set-Cookie</param-value>
</init-param>
<init-param>
<param-name>cors.supportsCredentials</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CORS</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
注意:当报403时cors.supportedHeaders 查看请求头