我想在tomcat容器中设置默认的http标头-
访问控制允许来源:*
从stackoverslow和Google的各种不同链接中,大多数都指向一种资源。这再次说明了如何做。我已经复制了相同的内容,但是仍然没有显示标题。这是我所做的:1)在tomcat的/ lib文件夹中复制cors.jar文件2)在web.xml中插入此文本
<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>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>
它不起作用,我很无助。我的tomcat版本是-6.0.6。请帮忙。
由于未将jar文件作为项目的一部分而出现该问题。我只是将其包含在tomcat lib中。web.xml现在可以在工程中使用以下内容:
jar
web.xml
<filter> <filter-name>springSecurityFilterChain</filter-name> <filter-class> org.springframework.web.filter.DelegatingFilterProxy </filter-class> </filter> <filter-mapping> <filter-name>springSecurityFilterChain</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <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.supportsCredentials</param-name> <param-value>false</param-value> </init-param> <init-param> <param-name>cors.supportedHeaders</param-name> <param-value>accept, authorization, origin</param-value> </init-param> <init-param> <param-name>cors.supportedMethods</param-name> <param-value>GET, POST, HEAD, OPTIONS</param-value> </init-param> </filter> <filter-mapping> <filter-name>CORS</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
并且下面是您的项目依赖项:
<dependency> <groupId>com.thetransactioncompany</groupId> <artifactId>cors-filter</artifactId> <version>1.3.2</version> </dependency>