关于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 ...
随机推荐
- android自己定义圆盘时钟
自己定义圆盘时钟的大概流程:由于圆盘时钟的圆盘是不须要动的,所以不必要加在自己定义的view里面,在view里面仅仅须要绘制秒针和分针时针并控其转动就可以. 下面就是自己定义view的主要代码: pa ...
- Classes and functions
As another example of a user-defined type, we’ll define a class called Time that records the time of ...
- 5.array
#include <iostream> #include <array> #include <algorithm> using namespace std; //a ...
- POJ 3668 枚举?
枚举两点,算一下斜率 sort一遍 判个重 输出解 25行 搞定- //By SiriusRen #include <cmath> #include <cstdio> #inc ...
- 修改host方法
打开路径 C:\Windows\System32\drivers\etc 将hosts文件拷贝出来修改之后放回去覆盖即可 以下是一个例子,想得到ip可以先ping一下那个域名. 左边是ip,右边是域名 ...
- 不再安全的 OSSpinLock
自旋锁的本质是持续占有cpu,直到获取到资源.与其他锁的忙等待的实现机制不同. 昨天有位开发者在 Github 上给我提了一个 issue,里面指出 OSSpinLock 在新版 iOS 中已经不能再 ...
- 重复执行shell脚本。
while ((1)); do gclient runhooks; sleep 2; donewhile ((1)); do ifconfig; sleep 1; done
- ES6学习5 字符串的扩展
1.ES6 为字符串添加了遍历器接口,使得字符串可以被for...of循环遍历. for (let codePoint of 'foo') { console.log(codePoint) } // ...
- 移动端 Modal 组件开发杂谈
Vant 是有赞开发的一套基于 Vue 2.0 的 Mobile 组件库,在开发的过程中也踩了很多坑,今天我们就来聊一聊开发一个移动端 Modal 组件(在有赞该组件被称为 Popup )需要注意的一 ...
- ECNUOJ 2142 放书
放书 Time Limit:1000MS Memory Limit:65536KBTotal Submit:409 Accepted:173 Description 你要把一叠书放进一些箱子里面,为 ...