Tomcat Ajax跨域訪問

http://ibleave60.blog.51cto.com/2669415/1208652html

http://enable-cors.org/server.htmljava

下載cors-filter-1.7.jar,java-property-utils-1.9.jar這兩個庫文件,放到lib目錄下。(可在http://search.maven.org上查詢並下載。)工程項目中web.xml中的配置以下:  web

<param-name>cors.allowOrigin</param-name>跨域

<param-value>這裏能夠不寫* 能夠指定站點域名 http://192.168.1.102</param-value>app

 

    <!-- 實現跨域 -->
    <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>
相關文章
相關標籤/搜索