关于springmvc重定向后Cannot create a session after the response has been committed问题
首先先上代码吧,我在用springmvc进行response.sendRedirect(url);操作后报了Cannot create a session after the response has been committed错误。
@RequestMapping(value={"","/"})
public String index(HttpServletResponse response,HttpServletRequest request) throws Exception{
// String callbackurl = "http://127.0.0.1:8080/sucstepms/index/goqrcodescansign";
String callbackurl = request.getRequestURL().toString();
Authorize au = new Authorize(appKey, appSecret);
String code = request.getParameter("code");
String url = au.forwardurl(callbackurl, "test", Authorize.DISPLAY_TAG_T.WEB);
if ( code == null || code.isEmpty() ){
response.sendRedirect(url);
return null;
}else{
String text=au.querytoken(code, callbackurl);
Map<String, Object> map=JSON.parseObject(text);
String token=(String) map.get("access_token");
if(token==null){
response.sendRedirect(url);
return null;
}else{
User user=new User(token);
System.out.println(user.me());
System.out.println(text+"--------------");
}
}
return "sign/front/guide";
}
在之前是没有加return null的,在执行重定向后悔跳到最后执行springmvc的return 页面操作。所以会报这个错误。所以解决办法就是加上return null;
我觉得这个问题的主要原因就在重定向response提交后,后面springmvc继续重定向了页面,或者多session有某些操作,所以会报这种错误。
关于springmvc重定向后Cannot create a session after the response has been committed问题的更多相关文章
- idea调试SpringMvc, 出现:”javax.servlet.ServletException: java.lang.IllegalStateException: Cannot create a session after the response has been committed"错误的解决方法
调试拦截器出现以下错误: HTTP Status 500 - javax.servlet.ServletException: java.lang.IllegalStateException: Cann ...
- Cannot create a session after the response has been committed
有时候在操作Session时,系统会抛出如下异常 java.lang.IllegalStateException: Cannot create a session after the response ...
- [Exceptions Spring 2] - Cannot create a session after the response has been committed
2016-02-23 14:06:27,416 [http-bio-8080-exec-1] DEBUG [org.springframework.beans.factory.support.Defa ...
- CAS-ERR Cannot create a session after the response has been committed
现象: 当cas 登录人数较少时候没有错误,但是用户过多时候出现下列err May-2016 18:09:11.932 SEVERE [http-nio-8080-exec-52] org.apach ...
- grails中报Cannot create a session after the response has been committed异常的解决办法
在grails中,我们在layouts\main.gsp中使用类似如下的代码来判断当前用户处于登录状态时显示相关的登录信息: <g:if test="${session.users}& ...
- springmvc重定向请求。
SpringMVC重定向传参数的实现(来自网友) 验证了我说的,从model层中拿来的数据,不管什么类型,都是通过隐含模型,中转,放入request中的.除非你特意把这些数据放到session域中. ...
- SpringMVC重定向路径中带中文参数
SpringMVC重定向路径中带中文参数 springboot重定向到后端接口测试 package com.mozq.http.http_01.demo; import org.springframe ...
- 什么时候会进行 SpringMVC重定向保存参数(FlashMap)?
SpringMVC重定向保存参数(FlashMap):两种情况会保存参数: 1. 当前视图为RedirectView,也即是说当前请求为重定向请求. org.springframe ...
- Springboot中登录后关于cookie和session拦截案例
目录 一.前言 二.利用Cookie进行登录验证 一.前言 1.简单的登录验证可以通过Session或者Cookie实现. 2.每次登录的时候都要进数据库校验下账户名和密码,只是加了cookie 或s ...
随机推荐
- 2015 Multi-University Training Contest 1 y sequence
Y sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- 使用JMX透过防火墙远程监控tomcat服务
https://my.oschina.net/mye/blog/64879 http://blog.csdn.net/l1028386804/article/details/51547408 http ...
- POJ——T1860 Currency Exchange
http://poj.org/problem?id=1860 Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 29874 ...
- mysql-组合查询
一.组合查询 mysql允许执行多个查询(多条select语句),并将结果作为单个查询结果集返回.这些组合查询通常称为并(union)或复合查询(compound query). 有两种情况需要使用组 ...
- 6、python中的字符串
最早的编码为ascii码,共256个符号.UTF-8是国际通用编码,全面支持中文,以一个字节表示英文,以三个字节表示一个中文以及其他语言:GB2312是我国自己定制的中文编码标准,使用1个字节表示英文 ...
- Vue小技巧,如何导入普通JS文件
最近在开发一个展示3D模型的WEB程序,在工程中使用了VUE和ThreeJS库.Three.js本身是支持CommonJS的,但我们还用到了OBJLoader模块,此模块不支持CommonJS,改成C ...
- ★★★【卡法 常用js库】: js汇合 表单验证 cookie设置 日期格式 电话手机号码 email 整数 小数 金额 检查参数长度
[卡法 常用js库]: js汇合 表单验证 cookie设置 日期格式 电话手机号码 email 整数 小数 金额 检查参数长度 // +---------------------- ...
- tomcat和nginx相互结合的优化调整
在工作中遇到这样的情况 Tomcat为后台 nginx为反向代理 需要往后台导入数据,由于处理时间过长,导致访问时出现504和500 通过修改tomcat中maxParameterCount=&qu ...
- 使用物化视图解决GoldenGate不能使用中文表名问题
源端: conn sh/sh create table "学生" ("学号" number primary key,"姓名" varchar ...
- python(2) 图像通道,几何变换,裁剪
一.图像通道 1.彩色图像转灰度图 from PIL import Image import matplotlib.pyplot as plt img=Image.open('d:/ex.jpg') ...