Cors Cross domain request, configure Access-control-allow-origin: "*", Invalid solution __java related

Source: Internet
Author: User


Because the application needs Cross-domain request data, the blogger in JDK8, Tomcat7.0 cors can configure Access-control-allow-origin: "*", but I did not take effect following the document configuration, once suspected that the problem is tomcat or JDK, In the end, Web.xml is loaded in the same order as in the past. Solution: Is the filter location problem, you put the whole into the first filter position is OK. Give the Web.xml:

<?xml version= "1.0" encoding= "UTF-8"?>

<web-app id= "webapp_id" version= "2.4"

xmlns= "Http://java.sun.com/xml/ns/j2ee" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"

xsi:schemalocation= "Http://java.sun.com/xml/ns/j2eehttp://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >

<display-name>och</display-name>

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:spring/spring-*.xml</param-value>

</context-param>

<listener>

<context-param>

<param-name>webAppRootKey</param-name>

<param-value>och.root</param-value>

</context-param>

<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>

</listener>

<listener>

<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

<!--enable Spring's scope= ' request '-->

<listener>

<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>

</listener>

<!--CORS 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>

<filter>

<filter-name>characterEncodingFilter</filter-name>

<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>

<init-param>

<param-name>encoding</param-name>

<param-value>UTF-8</param-value>

</init-param>

<init-param>

<param-name>ForceEncoding</param-name>

<param-value>true</param-value>

</init-param>

</filter>

<filter-mapping>

<filter-name>characterEncodingFilter</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

<filter>

<filter-name>control</filter-name>

<filter-class>com.cmos.core.filter.IControlRequestFilter</filter-class>

<init-param>

<param-name>controlRequestImpl</param-name>

<param-value>com.cmos.och.control.impl.ControlRequestImpl</param-value>

</init-param>

<init-param>

<param-name>controlFilePath</param-name>

<param-value>config/control.xml</param-value>

</init-param>

<init-param><!--internationalization config-->

<param-name>locale</param-name>

<param-value>zh_CN</param-value>

</init-param>

</filter>

<filter-mapping>

<filter-name>control</filter-name>

<url-pattern>/front/*</url-pattern>

</filter-mapping>

<filter>

<filter-name>struts2</filter-name>

<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>

</filter>

<filter-mapping>

<filter-name>struts2</filter-name>

<url-pattern>/front/*</url-pattern>

</filter-mapping>

</web-app>




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.