Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

代码赘余 #7

Open
RaySunWHUT opened this issue Nov 11, 2019 · 0 comments
Open

代码赘余 #7

RaySunWHUT opened this issue Nov 11, 2019 · 0 comments

Comments

@RaySunWHUT
Copy link

老哥,
JWTFilter.java中的这段:
/**
* 对跨域提供支持
*/
@OverRide
protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception {

    HttpServletRequest httpServletRequest = (HttpServletRequest) request;
    HttpServletResponse httpServletResponse = (HttpServletResponse) response;
    httpServletResponse.setHeader("Access-control-Allow-Origin", httpServletRequest.getHeader("Origin"));
    httpServletResponse.setHeader("Access-Control-Allow-Methods", "GET,POST,OPTIONS,PUT,DELETE");
    httpServletResponse.setHeader("Access-Control-Allow-Headers", httpServletRequest.getHeader("Access-Control-Request-Headers"));

    // 跨域时会首先发送一个option请求,这里我们给option请求直接返回正常状态
    if (httpServletRequest.getMethod().equals(RequestMethod.OPTIONS.name())) {

        httpServletResponse.setStatus(HttpStatus.OK.value());

        return false;

    }

    return super.preHandle(request, response);

}

对跨域的支持已经淘汰了,直接@crossorigin解决一切问题!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant