项目下面添加库:
cors-filter-1.7.jar
java-property-utils-1.9.jar
项目的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>
注意:访问文件夹无效,例如 localhost/myProj
访问文件有效:locaohost/myProj/index.jsp
这个lib做了优化,不是跨域访问的时候,header是不加跨域信息的,捕获包看不到。
标签:跨域,访问,配置,myProj,cors,filter,tomcat6,CORS From: https://blog.51cto.com/u_16076050/6196094