配置tomcat允许跨域访问,cors跨域资源共享

1.导入cors-filter-1.7.jar,java-property-utils-1.9.jar两个jar包

2.在web.xml里配上:

<filter>
        <filter-name>CORSfilter-name>
        <filter-class>com.thetransactioncompany.cors.CORSFilterfilter-class>
        <init-param>
            <param-name>cors.allowOriginparam-name>
            <param-value>*param-value>
        init-param>
        <init-param>
            <param-name>cors.supportedMethodsparam-name>
            <param-value>GET, POST, HEAD, PUT, DELETEparam-value>
        init-param>
        <init-param>
            <param-name>cors.supportedHeadersparam-name>
            <param-value>Accept, Origin, X-Requested-With, Content-Type, Last-Modifiedparam-value>
        init-param>
        <init-param>
            <param-name>cors.exposedHeadersparam-name>
            <param-value>Set-Cookieparam-value>
        init-param>
        <init-param>
            <param-name>cors.supportsCredentialsparam-name>
            <param-value>trueparam-value>
        init-param>
    filter>
    <filter-mapping>
        <filter-name>CORSfilter-name>
        <url-pattern>/*url-pattern>
    filter-mapping>

 

转载于:https://www.cnblogs.com/cnsdhzzl/p/8473812.html

你可能感兴趣的:(配置tomcat允许跨域访问,cors跨域资源共享)