Java利用cors实现跨域请求

(一) 首先下载jar包
cors-filter与java-property-utils
https://mvnrepository.com/artifact/com.thetransactioncompany/cors-filter
https://mvnrepository.com/artifact/com.thetransactioncompany/java-property-utils
(二)修改工程中的web.xml
增加以下代码(最好放在其他filter前边)

CORS
com.thetransactioncompany.cors.CORSFilter

cors.allowOrigin
*


cors.supportedMethods
GET, POST, HEAD, PUT, DELETE


cors.supportedHeaders
Accept, Origin, X-Requested-With, Content-Type, Last-Modified


cors.exposedHeaders
Set-Cookie


cors.supportsCredentials
true


CORS
/*

(三)前端请求配置withCredentials属性为true

你可能感兴趣的:(Java利用cors实现跨域请求)