ajax报错Access to XMLHttpRequest at ‘xxx’ from origin ‘xxx’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource
原先以为是跨域设置有问题,检查@CrossOrigin和配置类没问题后,终于发现了问题所在:
jsp页面使用localhost进行ajax操作,跨域时jsp页面就会出现这种报错,推荐使用<%bathpath%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>