Tomcat跨域

先下载 cors-filter-2.6.jar  2.java-property-utils-1.9.1.jar,这两个文件有些在csdn上积分太高,有些要百度网盘,还要下载百度网盘客户端,太麻烦,直接在pom.xml中配置,然后让ide直接去下载就好了,然后去找到这两个文件复制出来即可,pom.xml增加如下配置(maven):

1
2
3
4
5
6
<!-- https://mvnrepository.com/artifact/com.thetransactioncompany/cors-filter -->
<dependency>
    <groupId>com.thetransactioncompany</groupId>
    <artifactId>cors-filter</artifactId>
    <version>2.6</version>
</dependency>

web.xml的配置,从网上抄的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<filter>
        <filter-name>CORS</filter-name>
        <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
        <init-param>
            <param-name>cors.allowOrigin</param-name>
            <param-value>*</param-value>
        </init-param>
        <init-param>
            <param-name>cors.supportedMethods</param-name>
            <param-value>GET,POST,HEAD,PUT,DELETE</param-value>
        </init-param>
        <init-param>
            <param-name>cors.supportedHeaders</param-name>
            <param-value>Accept,Origin,X-Requested-With,Content-Type,Last-Modified</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> 

如果处理好没效果,就试试重启tomcat

posted @   唯起  阅读(346)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示