zoukankan      html  css  js  c++  java
  • ajax跨域

    原文:https://segmentfault.com/a/1190000012469713

    整理jar包:https://files.cnblogs.com/files/BambooLamp/ajax%E8%B7%A8%E5%9F%9Fjar%E5%8C%85.zip

    添加CORS配置到项目的Web.xml中( App/WEB-INF/web.xml)

    <!-- 跨域配置-->    
    <filter>
            <!-- The CORS filter with parameters -->
            <filter-name>CORS</filter-name>
            <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
            
            <!-- Note: All parameters are options, if omitted the CORS 
                 Filter will fall back to the respective default values.
              -->
            <init-param>
                <param-name>cors.allowGenericHttpRequests</param-name>
                <param-value>true</param-value>
            </init-param>
            
            <init-param>
                <param-name>cors.allowOrigin</param-name>
                <param-value>*</param-value>
            </init-param>
            
            <init-param>
                <param-name>cors.allowSubdomains</param-name>
                <param-value>false</param-value>
            </init-param>
            
            <init-param>
                <param-name>cors.supportedMethods</param-name>
                <param-value>GET, HEAD, POST, OPTIONS</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>
                <!--这里可以添加一些自己的暴露Headers   -->
                <param-value>X-Test-1, X-Test-2</param-value>
            </init-param>
            
            <init-param>
                <param-name>cors.supportsCredentials</param-name>
                <param-value>true</param-value>
            </init-param>
            
            <init-param>
                <param-name>cors.maxAge</param-name>
                <param-value>3600</param-value>
            </init-param>
    
        </filter>
    
        <filter-mapping>
            <!-- CORS Filter mapping -->
            <filter-name>CORS</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>

    请注意,以上配置文件请放到web.xml的前面,作为第一个filter存在(可以有多个filter的)

    可能的安全模块配置错误(注意,某些框架中-譬如公司私人框架,有安全模块的,有时候这些安全模块配置会影响跨域配置,这时候可以先尝试关闭它们)

    感谢原作者:撒网要见鱼

  • 相关阅读:
    MySQL性能调优语句
    APP测试
    JForum项目搭建
    Bug的等级及定位
    mysql any和all的用法
    mysql产生随机数
    MySQL存储过程例子
    【转】 卡特兰数
    牛客小白月赛5 I 区间 (interval) 【前缀和】
    牛客小白月赛5 D 阶乘(factorial) 【前缀】
  • 原文地址:https://www.cnblogs.com/BambooLamp/p/12603299.html
Copyright © 2011-2022 走看看