前端通过XHR请求后端服务时,出现了下图现象:
根据问题的描述可知,是遇到跨域问题了,为了支持跨域,需要在后端做一下处理,可以这样处理:
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; response.setHeader("Access-Control-Allow-Methods", "POST, GET, PATCH, DELETE, PUT, OPTIONS"); filterChain.doFilter(servletRequest, servletResponse); }
具体的添加过程,可以参考此链接