码迷,mamicode.com
首页 > 其他好文 > 详细

Tomcat 跨域问题的解决

时间:2018-07-26 13:04:45      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:pat   img   web.xml   ping   The   edm   modified   put   com   

 先下载CORS对应的Jar:

技术分享图片

 下载链接: https://download.csdn.net/download/u010739157/10565169

    在tomcat的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> 

 

   重启tomcat后测试。

 

Tomcat 跨域问题的解决

标签:pat   img   web.xml   ping   The   edm   modified   put   com   

原文地址:https://www.cnblogs.com/zhaoyanhaoBlog/p/9370830.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!