Tomcat6、tomcat7 跨域设置

来源:互联网 发布:淘宝电信旗舰店 编辑:程序博客网 时间:2024/05/26 05:16

需要下载两个jar文件,cors-filter-1.7.jar,java-property-utils-1.9.jar这两个库文件,http://download.csdn.net/detail/csr0312/9280097
放到tomcat lib目录下面,不是项目的lib目录,然后配置项目的web.xml,添加如下内容,注意filter位置,应该放在第一位

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