美文网首页开源Tomcat
tomcat解决跨域问题

tomcat解决跨域问题

作者: WebGiser | 来源:发表于2018-12-31 17:03 被阅读2次

1、打开tomcat安装目录 -> 打开 conf 目录 -> 打开web.xml文件
2、将如下代码复制到web.xml文件中(我是放在 /400左右的位置,不要放在最前面和最后面,一定要放中间)

  <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>
        <init-param>
            <param-name>cors.allowed.methods</param-name>
            <param-value>GET,POST,HEAD,OPTIONS,PUT</param-value>
        </init-param>
        <init-param>
            <param-name>cors.allowed.headers</param-name>
            <param-value>*</param-value>
        </init-param>
        <init-param>
            <param-name>cors.exposed.headers</param-name>
            <param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value>
        </init-param>
        <init-param>
            <param-name>cors.support.credentials</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>CorsFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

相关文章

网友评论

    本文标题:tomcat解决跨域问题

    本文链接:https://www.haomeiwen.com/subject/fykwlqtx.html