Tomcat Ajax跨域访问

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

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

下载cors-filter-1.7.jar,java-property-utils-1.9.jar这两个库文件,放到lib目录下。(可在http://search.maven.org上查询并下载。)工程项目中web.xml中的配置如下:  

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

<param-value>这里可以不写* 可以指定站点域名 http://192.168.1.102</param-value>

 

    <!-- 实现跨域 -->
    <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>

 

posted @ 2013-12-10 20:50  大新博客  阅读(4534)  评论(0编辑  收藏  举报