webmvc 拦截器 允许跨域 跨域问题 sessionid不一样
package cn.com.yitong.ares.filter;
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;
import javax.ws.rs.HttpMethod;
import org.apache.http.HttpStatus;
public class CORSFilter implements Filter{
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletResponse httpResponse = (HttpServletResponse) servletResponse;
HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
httpResponse.addHeader("Access-Control-Allow-Origin", httpRequest.getHeader("Origin"));
httpResponse.setHeader("Access-Control-Max-Age", "3600");
httpResponse.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS, DELETE");
httpResponse.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
httpResponse.setHeader("Access-Control-Allow-Credentials", "true");
if (HttpMethod.OPTIONS.equals(httpRequest.getMethod())) {
httpResponse.setStatus(HttpStatus.SC_NO_CONTENT);
return;
}
filterChain.doFilter(servletRequest, httpResponse);
}
@Override
public void destroy() {
}
}
package cn.com.yitong.ares;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* 跨域配置
*
*
* @date 2020-04-20 16:46
* @since 1.0.0
*/
@Configuration
@EnableWebMvc
public class CorsConfiguration implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
// 设置允许跨域的路径
registry.addMapping("/**")
// 设置允许跨域请求的域名
.allowedOrigins("*")
// 是否允许证书 不再默认开启
.allowCredentials(true)
// 设置允许的方法
.allowedMethods("*")
// 跨域允许时间
.maxAge(3600);
}
}
webmvc 拦截器 允许跨域 跨域问题 sessionid不一样的更多相关文章
- vue cli+axios踩坑记录+拦截器使用,代理跨域proxy(更新)
16319 1.首先axios不支持vue.use()方式声明使用,看了所有近乎相同的axios文档都没有提到这一点建议方式 在main.js中如下声明使用 import axios from 'ax ...
- vue cli+axios踩坑记录+拦截器使用,代理跨域proxy
1.首先axios不支持vue.use()方式声明使用,看了所有近乎相同的axios文档都没有提到这一点 建议方式 在main.js中如下声明使用 import axios from 'axios'; ...
- Java Web学习(十)Java拦截器
文章更新时间:2020/04/07 一.引言 既然要用拦截器,首先先得简单了解一下什么是拦截器: 概念:java里的拦截器是动态拦截Action调用的对象,它提供了一种机制可以使开发者在一个Actio ...
- Spring Boot配置拦截器及实现跨域访问
拦截器功能强大,能够深入方法前后,常应用于日志记录.权限检查和性能检测等,几乎是项目中不可或缺的一部分,本文就来实现Spring Boot自定义拦截器的配置. 理论指导 问:Spring Boot怎么 ...
- axios踩坑记录+拦截器使用+vue cli代理跨域proxy+webpack打包部署到服务器
1.小小的提一下vue cli脚手架前端调后端数据接口时候的本地代理跨域问题,如我在本地localhost访问接口http://40.00.100.100:3002/是要跨域的,相当于浏览器设置了一道 ...
- 04 DRF内容回顾、用户登录 (含跨域) (vuex vue-cookie)、用户认证 (Auth认证)(拦截器)
1.内容回顾 1.视图中常见的继承 2.频率访问控制源码 3.序列化,反序列化 2.初始化代码 1.后端代码:AuthView (1)目录结构 (2)urls (3)view (4)注释掉cors ( ...
- 【跨域】SpringBoot跨域,拦截器中,第一次获取的请求头为NULL,发送两次请求的处理方式
背景: 在做前后端分离时,牵扯到跨域,但是已经设置了跨域 前端设置了允许携带Cookie axios.defaults.withCredentials = true; 后端也配置了跨域 浏览器端查看发 ...
- JS跨域:1.解决方案之-SpringMVC拦截器
一 拦截器代码 package com.wiimedia.controller; import java.util.List; import javax.servlet.http.HttpServle ...
- 通过Html5的postMessage和onMessage方法实现跨域跨文档请求访问
在项目中有应用到不同的子项目,通过不同的二级域名实现相互调用功能.其中一个功能是将播放器作为单独的二级域名的请求接口,其他项目必须根据该二级域名调用播放器.最近需要实现视频播放完毕后的事件触发,调用父 ...
随机推荐
- Presto安装完成之后需要做的
Presto因其优秀的查询速度被我们所熟知,它本身基于MPP架构,可以快速的对Hive数据进行查询,同时支持扩展Connector,目前对Mysql.MongoDB.Cassandra.Hive等等一 ...
- ProGuard使用文档
介绍 是一个对于Java字节码的免费的压缩器,优化器,混淆器和审核器: l 它检测并删除未使用的类,字段,方法和属性. l 它优化字节码并删除未使用的指令. l 它重命名其余类.字段和方法使用短 ...
- List<bean> 转换成List<Map>
//将listmap转换成list实体类 List<OaAttachment>list=new ArrayList<OaAttachment>(); if(Func.isNot ...
- 多维数组遍历.php
$a=array('fruits'=>array('a'=>'orange','b'=>'grape','c'=>'apple'), 'numbers'=>arr ...
- jdbc编程学习(1)
一,背景 1996年,sun公司发布了第一版本的数据库连接(JDBC)API,使编程人员可以通过这个API接口连接到数据库,并使用结构化查询语言(SQL)完成对数据库的查找与更新.JDBC自此成为Ja ...
- new 的原理和实现
new 运算符内部做了如下四个操作: 创建一个空的简单 JavaScript 对象(即{}): 链接新对象(即设置该新对象的构造函数)到函数对象: 将新创建的对象作为 this 的上下文: 如果该函数 ...
- java数组之system.arrayCopy
public class ArrayDemo { /* public static void main(String[] args) { int[] a=new int[4]; int[] b=new ...
- erlang开发环境(IDE)搭建
1.首先推荐:intellij idea http://www.open-open.com/news/view/44c90e 2.webstorm: http://plugins.jetbrains. ...
- c通过ctfshow学习php反序列化
web254 web255 web256 web257 web258 web259 web260 web262 web263 web264 web265 web266 web254 error_rep ...
- spark的thriftservr的高可用
triftserver是基于jdbc的一个spark的服务,可以做web查询,多客户端访问,但是thriftserver没有高可用,服务挂掉后就无法在访问,所有使用注册到zk的方式来实现高可用 一.版 ...