当前位置:网站首页>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 )
边栏推荐
- 2021.9.29学习日志-MIME类型
- 移动端适配方案
- Leetcode judge subsequence simple
- MySQL fuzzy query and sorting by matching degree
- Power simple of leetcode-3
- Ffmpeg download suffix is Video files for m3u8
- Leetcode planting flowers - simple
- Service fusing and degradation of Note Series
- Etcd fast cluster building
- ffmpeg 下载后缀为.m3u8的视频文件
猜你喜欢
2 first experience of drools
The SQL file of mysql8.0 was imported into version 5.5. There was a pit
How MySQL optimizes the use of joint index ABC
Missing tag identification in cots RFID systems: bringing the gap between theory and Practice
Interrupt processing
powershell优化之一:提示符美化
MySQL fuzzy query and sorting by matching degree
Zero copy technology
Working principle of sentinel series (concept)
軟件測試——接口常見問題匯總
随机推荐
powershell优化之一:提示符美化
Leetcode- number of maximum consecutive ones - simple
2021.9.29 learning log restful architecture
High availability of Nacos series
Leetcode- hex number - simple
移动端适配方案
Leetcode- detect uppercase letters - simple
Test logiciel - résumé des FAQ d'interface
How MySQL optimizes the use of joint index ABC
Building a stand-alone version of Nacos series
AUTOSAR actual combat tutorial pdf version
Leetcode- longest palindrome string - simple
Leetcode minimum absolute difference of binary search tree simple
Three paradigms of MySQL
Misunderstanding of tongweb due to ease of use
2021.9.29学习日志-Restful架构
Mobile end adaptation scheme
MySQL fuzzy query and sorting by matching degree
Tongweb card, tongweb card, tongweb card
Power of leetcode-4 - simple