关于配置cors跨域
来源:互联网 发布:puppy linux吧 编辑:程序博客网 时间:2024/06/06 01:45
普通web项目:
1.首先引入jar包
在lib文件夹中添加jar
1)cors-filter-2.4.jar
2)java-property-utils-1.9.1.jar
2.在web.xml中加入配置
webapp节点下加入如下编码:
<filter><filter-name>CORS</filter-name><filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class></filter><filter-mapping><filter-name>CORS</filter-name><servlet-name>/*</servlet-name></filter-mapping><filter-mapping><filter-name>CORS</filter-name><url-pattern>/*</url-pattern></filter-mapping>
相关网页:http://software.dzhuvinov.com/cors-filter-installation.html
springboot项目:
经过尝试在pom.xml引入依赖,再配置web.xml,这个方法没有跨域成功。
正确方式:在src/package任意地方新建类
package com.monetware.config;import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; @Configuration public class CorsConfig extends WebMvcConfigurerAdapter { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") .allowedOrigins("*") .allowCredentials(true) .allowedMethods("GET", "POST", "DELETE", "PUT") .maxAge(3600); } }
这样就解决了跨域问题
0 0
- 关于配置cors跨域
- cors跨域 web.config配置
- CORS跨域,java开发配置
- CORS跨域
- 跨域 CORS
- cors 跨域
- 跨域-CORS
- cors 跨域
- 跨域CORS
- cors跨域
- CORS跨域
- 跨域CORS
- 跨域cors
- 腾讯云cors配置
- Spring MVC配置CORS
- Spring关于CORS跨域支持的全局配置(代码实战)
- 关于对CORS 的了解
- 2. nginx CORS 的配置
- apache设置默认首页
- Java 动态代理机制分析及扩展(1)
- ios基本控件之UITextField
- SpringMVC 集成tiles时报 Connection timed out
- iOS开发系列--通知与消息机制
- 关于配置cors跨域
- IntelliJ IDEA 14 + Phonegap 5.1 + Android SDK + Genymotion + linux
- spoj LCMSUM
- [文章摘要]Semantic Enrichment and Analysis of Movement Data:Probably it is just Starting!
- JavaScript 自调用匿名函数
- SQL语句优化技巧
- SQL日期操作
- Android面试题3
- 关于栈深度