当前位置:网站首页>CORS request principle
CORS request principle
2022-06-13 05:54:00 【A programmer in a wig】
CORS Principle of request
CORS It's a W3C standard , The full name is " Cross-domain resource sharing "(Cross-origin resource sharing). It allows the browser to cross to the source server , issue XMLHttpRequest request , To overcome AJAX A restriction that can only be used with the same origin .
Basically all current browsers have implemented CORS standard , In fact, almost all browsers at present ajax Requests are based on CORS The mechanism , It's just that front-end developers may not care about it at ordinary times ( So now CORS The solution is mainly to consider how the background should be implemented ).
JAVA The background configuration
JAVA The background configuration only needs to follow the following steps :
First step : Get dependency jar package
download cors-filter-1.7.jar, java-property-utils-1.9.jar These two library files are put into lib Under the table of contents .( Put it in the corresponding item webcontent/WEB-INF/lib/ Next )
The second step : If the project uses Maven Built , Please add the following dependencies to pom.xml in :( Not maven Please ignore )
<dependency>
<groupId>com.thetransactioncompany</groupId>
<artifactId>cors-filter</artifactId>
<version>[ version ]</version>
</dependency>
The version should be the latest stable version ,CORS filter
The third step : add to CORS Configuration to project Web.xml in ( App/WEB-INF/web.xml)
<!-- Cross domain configuration -->
<filter>
<!-- The CORS filter with parameters -->
<filter-name>CORS</filter-name>
<filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
<!-- Note: All parameters are options, if omitted the CORS Filter will fall back to the respective default values. -->
<init-param>
<param-name>cors.allowGenericHttpRequests</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cors.allowOrigin</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>cors.allowSubdomains</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>cors.supportedMethods</param-name>
<param-value>GET, HEAD, POST, OPTIONS</param-value>
</init-param>
<init-param>
<param-name>cors.supportedHeaders</param-name>
<param-value>Accept, Origin, X-Requested-With, Content-Type, Last-Modified</param-value>
</init-param>
<init-param>
<param-name>cors.exposedHeaders</param-name>
<!-- Here you can add some of your own exposure Headers -->
<param-value>X-Test-1, X-Test-2</param-value>
</init-param>
<init-param>
<param-name>cors.supportsCredentials</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cors.maxAge</param-name>
<param-value>3600</param-value>
</init-param>
</filter>
<filter-mapping>
<!-- CORS Filter mapping -->
<filter-name>CORS</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Please note that , Please put the above configuration files in web.xml In front of , As the first filter There is ( There can be multiple filter Of )
边栏推荐
- @Detailed explanation of propertysource usage method and operation principle mechanism
- 2021.9.30 learning log -postman
- Service fusing and degradation of Note Series
- Software testing - Summary of common interface problems
- Top slide immersive dialog
- 2021.9.29 learning log MIME type
- Mongodb Multi - field Aggregation group by
- MongoDB 多字段聚合Group by
- AUTOSAR实战教程pdf版
- Nacos series registry principle and source code analysis
猜你喜欢
软件测试——接口常见问题汇总
How slow is the application system on tongweb? How dead is it?
MySQL performs an inner join on query. The query result is incorrect because the associated fields have different field types.
Etcd understanding of microservice architecture
Experience of redis installation under Linux system (an error is reported at the same time. The struct redis server does not have a member named XXXX)
Tongweb card, tongweb card, tongweb card
Function and application scenario of field setaccessible() method
Vagrant virtual machine installation, disk expansion and LAN access tutorial
Concurrent programming -- what is threading?
Explanation of sentinel series' features, composition and deployment
随机推荐
Leetcode guessing numbers game - simple
Four shardingsphere JDBC sharding strategies
Leetcode longest harmonic subsequence simple
AUTOSAR actual combat tutorial pdf version
Leetcode planting flowers - simple
Leetcode- intersection of two arrays ii- simple
Leetcode Timo attack - simple
About the solution of pychart that cannot be opened by double clicking
Explanation of sentinel series' features, composition and deployment
AUTOSAR实战教程pdf版
12 error end event and terminateendevent of end event
17 servicetask of flowable task
13 cancelendevent of a flowable end event and compensationthrowing of a compensation event
Leetcode- hex number - simple
移动端适配方案
2021.9.29 learning log restful architecture
ArrayList loop removes the pit encountered
1 Introduction to drools rule engine (usage scenarios and advantages)
Pychart encountered time zone problem when connecting to MySQL timezone
Current limiting and fusing of gateway gateway in Spirng cloud