cors
parent
fe0af58465
commit
7b1c4a8f66
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
*Copyright © 2018 anji-plus
|
||||||
|
*安吉加加信息技术有限公司
|
||||||
|
*http://www.anji-plus.com
|
||||||
|
*All rights reserved.
|
||||||
|
*/
|
||||||
|
package com.anjiplus.template.gaea.business.filter;
|
||||||
|
/**
|
||||||
|
* 本地启动解决跨域问题
|
||||||
|
* Created by raodeming on 2021/06/24.
|
||||||
|
*/
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import javax.servlet.*;
|
||||||
|
import javax.servlet.annotation.WebFilter;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@WebFilter(filterName = "CorsFilter ")
|
||||||
|
@Configuration
|
||||||
|
public class CorsFilter implements Filter {
|
||||||
|
@Override
|
||||||
|
public void init(FilterConfig filterConfig) throws ServletException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
|
||||||
|
throws ServletException, IOException {
|
||||||
|
HttpServletResponse response = (HttpServletResponse) servletResponse;
|
||||||
|
HttpServletRequest request = (HttpServletRequest) servletRequest;
|
||||||
|
response.setContentType("application/json; charset=utf-8");
|
||||||
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
response.setHeader("Access-Control-Max-Age", "3600");
|
||||||
|
response.setHeader("Access-Control-Allow-Methods", "POST, GET,PUT, OPTIONS, DELETE");//http请求方式
|
||||||
|
response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
|
||||||
|
response.setHeader("Access-Control-Allow-Credentials", "true");
|
||||||
|
response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, token");
|
||||||
|
filterChain.doFilter(request, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroy() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue