Tomcat cross-origin access and tomcat cross-origin access
What is cross-origin:
Simply put, the browser requests resources between several different domain names. For security reasons, the browser rejects cross-origin access by default, leading to resource acquisition failure.
Solution 1:
In tomcat.6.0.27 and later versions, there are simple solutions to cross-origin problems:
Edit context. xml in the conf directory of tomcat.
Modify the Context to the following:
<ContextsessionCookiePath = "" sessionCookieDomain = ". ×××. cn"/>
Solution 2:
Import cors-filter-1.7.jar, java-property-utils-1.9.jar two jar packages
Add the following in web. xml:
<! -- Implement cross-Origin -->
<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>