java后台接口SSM框架解決跨域問題


這幾天和前端對接接口,前端的錯誤信息是:

 

 注釋:
  Failed to load http://192.168.3.3:8080/Light_Push/webFrames.action?page=1&searchProject=1&page=1&searchProject=1: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin              'http://localhost:8080' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

前端用了vue,axios(http客戶端)
后端ssm框架,spring版本是3.2.13

發現可以從后台spring跨域着手解決

解決跨域方法:

第一步:導入jar包

  cors-filter-1.7.jar、java-property-utils-1.9.jar

  下載地址:http://pan.baidu.com/s/1pLkLPGJ

第二步:在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> 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>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM