cors支持跨域

<dependency>
   <groupId>com.thetransactioncompanygroupId>
   <artifactId>cors-filterartifactId>
   <version>1.7.1version>
dependency>
<dependency>
   <groupId>com.thetransactioncompanygroupId>
   <artifactId>java-property-utilsartifactId>
   <version>1.9.1version>
dependency>

web.xml添加
<filter>
  <filter-name>CORSfilter-name>
  <filter-class>com.thetransactioncompany.cors.CORSFilterfilter-class>
  <init-param>
    <param-name>cors.allowOriginparam-name>
    <param-value>*param-value>
  init-param>
  <init-param>
    <param-name>cors.supportedMethodsparam-name>
    <param-value>GET, POST, HEAD, PUT, DELETEparam-value>
  init-param>
  <init-param>
    <param-name>cors.supportedHeadersparam-name>
    <param-value>Accept, Origin, X-Requested-With, Content-Type, Last-Modifiedparam-value>
  init-param>
  <init-param>
    <param-name>cors.exposedHeadersparam-name>
    <param-value>Set-Cookieparam-value>
  init-param>
  <init-param>
    <param-name>cors.supportsCredentialsparam-name>
    <param-value>trueparam-value>
  init-param>
filter>
<filter-mapping>
  <filter-name>CORSfilter-name>
  <url-pattern>/*url-pattern>
filter-mapping>
前端:
$.ajax({
        url : 'http://remote.domain.com/corsrequest',
        data : data,
        dataType: 'json',
        type : 'POST',
        xhrFields: {
            withCredentials: true
        },
        crossDomain: true,
        contentType: "application/json",
        ...


你可能感兴趣的:(java)