Solved: No 'Access-Control-Allow-Origin' header is present on the requested resource' (cross-domain issue

This is a common cross-domain request problem. It is common in projects where front-end and back-end are separated. The request path in the front-end project directly uses the background request path (for example: http://192.168.1.1:8080/demo/getUser.do) , but According to the browser's network request rules, the background server does not allow such a direct call (it will be intercepted by malicious hackers). As a result, the cross-domain request is rejected (as shown in the figure below).

Access to XMLHttpRequest at ‘http://192.168.1.1:8080/app/easypoi/importExcelFile’ from origin ‘http://localhost:8080’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

Solution:

There are many ways to modify the configuration files in various projects on the Internet, but it is not easy to use. In fact: just modify a filtering configuration of the background Server (such as java's tomcat), that is, allow cross-domain requests;

Add the following configuration filter to the conf/web.xml configuration file of the requested server side (tomcat)

(Such as w "Analysis of Java Interview Questions in First-tier Manufacturers + Back-end Development Study Notes + Latest Architecture Explanation Video + Handouts on Practical Project Source Code" Free open source prestige search official account [Programming Advanced Road] When there are multiple filters in eb. Put the following configuration at the front end)

CorsFilter

org.apache.catalina.filters.CorsFilter

Guess you like

Origin blog.csdn.net/tt8889/article/details/124557405