欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

通过修复web.xml来实现跨域

程序员文章站 2024-01-31 20:31:04
...

通过修复web.xml来实现跨域

 

(1)在开发项目中加入支持库,或把支持库直接丢到tomcat的lib目录下,下载地址:http://cdn.besdlab.cn/cors-lib.rar

(2)修改web.xml,增加以下代码

 

<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>

 

相关标签: 跨域 CORS