<!-- | |
Enable CORS on Tomcat : Place under ${tomcat_home}/conf/web.xml | |
See http://enable-cors.org/server_tomcat.html and http://tomcat.apache.org/tomcat-7.0-doc/config/filter.html#CORS_Filter | |
--> | |
<!-- ================== CUSTOM Filter Definitions ===================== --> | |
<filter> | |
<filter-name>CorsFilter</filter-name> | |
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class> | |
<init-param> | |
<param-name>cors.allowed.origins</param-name> | |
<param-value>*</param-value> | |
</init-param> | |
<init-param> | |
<param-name>cors.allowed.methods</param-name> | |
<param-value>GET,POST,HEAD,OPTIONS,PUT</param-value> | |
</init-param> | |
<init-param> | |
<param-name>cors.allowed.headers</param-name> | |
<param-value>Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers</param-value> | |
</init-param> | |
<init-param> | |
<param-name>cors.exposed.headers</param-name> | |
<param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value> | |
</init-param> | |
<init-param> | |
<param-name>cors.support.credentials</param-name> | |
<param-value>true</param-value> | |
</init-param> | |
<init-param> | |
<param-name>cors.preflight.maxage</param-name> | |
<param-value>10</param-value> | |
</init-param> | |
</filter> | |
<filter-mapping> | |
<filter-name>CorsFilter</filter-name> | |
<url-pattern>/*</url-pattern> | |
</filter-mapping>
此方适用tomcat下的所有项目,如果需要单个项目请配置在项目的web.xml下面,并导入相应的包 |
tomcat配置cors实现跨域
最新推荐文章于 2025-03-17 00:23:36 发布