Cross-origin content separation between the front and back ends

Source: Internet
Author: User

Cross-origin content separation between the front and back ends
About front-end and back-end cross-origin separation 1. Support for cross-origin in spring, we just need to add this configuration in the configuration.

         
  
 
2. It seems that this configuration is not enough. You also need to add a filter for the project, as shown below:
package com.linktai.utils;import java.io.IOException;import javax.servlet.Filter;import javax.servlet.FilterChain;import javax.servlet.FilterConfig;import javax.servlet.ServletException;import javax.servlet.ServletRequest;import javax.servlet.ServletResponse;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;/** * Servlet Filter implementation class CrossFilter */public class CrossFilter implements Filter {  /**   * Default constructor.    */  public CrossFilter() {    // TODO Auto-generated constructor stub   }    /**     * @see Filter#destroy()     */    public void destroy() {        // TODO Auto-generated method stub    }    /**     * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)     */    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)            throws IOException, ServletException {        HttpServletRequest request = (HttpServletRequest) req;        HttpServletResponse response = (HttpServletResponse) resp;        response.setHeader("Access-Control-Allow-Origin", "https://pandabox.io");    response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");     response.setHeader("Access-Control-Max-Age", "3600");     response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");     response.setHeader("Access-Control-Allow-Credentials", "true");         chain.doFilter(req, resp);    }    /**     * @see Filter#init(FilterConfig)     */    public void init(FilterConfig fConfig) throws ServletException {        // TODO Auto-generated method stub    }}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.