spring-boot前后端分离跨域问题的解决,主要是使用cors
2018-09-14 08:43
1331 查看
代码如下
@Component public class CorsConfiguration implements Filter { public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletResponse response = (HttpServletResponse) res; HttpServletRequest reqs = (HttpServletRequest) req; response.setHeader("Access-Control-Allow-Origin",reqs.getHeader("Origin")); response.setHeader("Access-Control-Allow-Credentials", "true"); response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE,HEAD"); response.setHeader("Access-Control-Max-Age", "3600"); response.setHeader("Access-Control-Allow-Headers", "Content-Type"); if (reqs.getMethod().equals("OPTIONS")) { response.setStatus(response.SC_OK); response.getWriter().write("OPTIONS returns OK"); return; } chain.doFilter(req, res); } public void init(FilterConfig filterConfig) {} public void destroy() {} }阅读更多
相关文章推荐
- SpringBoot+Vue前后端分离,使用SpringSecurity完美处理权限问题的解决方法
- Spring Boot使用CORS解决跨域问题
- vue+springboot前后端分离实现单点登录跨域问题解决方法
- java 浅析跨域问题以及如何使用Cors解决前后端分离部署项目所遇到的跨域问题
- Spring Boot + Spring Cloud 实现权限管理系统 后端篇(十二):解决跨域问题
- 解决前后端分离的 CORS 跨域资源共享问题
- SpringBoot解决cors跨域问题
- springboot中通过cors协议解决跨域问题
- SpringBoot(六):SpringBoot使用CROS解决跨域问题
- SpringBoot+Vue前后端分离,使用SpringSecurity完美处理权限问题(二)
- springboot中通过cors协议解决跨域问题
- SpringBoot(六):SpringBoot使用CROS解决跨域问题
- springboot中通过cors协议解决跨域问题
- springboot中如何通过cors协议解决跨域问题
- vue前后端分离使用fetch 跨域请求时 session失效问题解决
- springboot前后端分离解决跨域
- springboot解决跨域问题(Cors)
- springboot -- 通过cors协议解决跨域问题
- SpringBoot+Vue前后端分离,使用SpringSecurity完美处理权限问题(六)
- springboot中通过cors协议解决跨域问题