Tomcat跨域配置:
1. 修改文件“项目名/WEB-INF/web.xml" ,如没有,则创建,配置如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <? xml version = "1.0" encoding = "UTF-8" ?> < web-app xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns = "http://java.sun.com/xml/ns/javaee" xsi:schemaLocation = "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id = "WebApp_ID" version = "3.0" > < 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 > </ filter > < filter-mapping > < filter-name >CorsFilter</ filter-name > < url-pattern >/*</ url-pattern > </ filter-mapping > </ web-app > |
2.重启Tomcat,即会生效。
暂无评论...