首先先上代码吧,我在用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问题的更多相关文章

  1. 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 ...

  2. Cannot create a session after the response has been committed

    有时候在操作Session时,系统会抛出如下异常 java.lang.IllegalStateException: Cannot create a session after the response ...

  3. [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 ...

  4. 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 ...

  5. grails中报Cannot create a session after the response has been committed异常的解决办法

    在grails中,我们在layouts\main.gsp中使用类似如下的代码来判断当前用户处于登录状态时显示相关的登录信息: <g:if test="${session.users}& ...

  6. springmvc重定向请求。

    SpringMVC重定向传参数的实现(来自网友) 验证了我说的,从model层中拿来的数据,不管什么类型,都是通过隐含模型,中转,放入request中的.除非你特意把这些数据放到session域中. ...

  7. SpringMVC重定向路径中带中文参数

    SpringMVC重定向路径中带中文参数 springboot重定向到后端接口测试 package com.mozq.http.http_01.demo; import org.springframe ...

  8. 什么时候会进行 SpringMVC重定向保存参数(FlashMap)?

    SpringMVC重定向保存参数(FlashMap):两种情况会保存参数:    1. 当前视图为RedirectView,也即是说当前请求为重定向请求.        org.springframe ...

  9. Springboot中登录后关于cookie和session拦截案例

    目录 一.前言 二.利用Cookie进行登录验证 一.前言 1.简单的登录验证可以通过Session或者Cookie实现. 2.每次登录的时候都要进数据库校验下账户名和密码,只是加了cookie 或s ...

随机推荐

  1. ActiveMQ maven

    http://outofmemory.cn/java/mq/apache-activemq-demo

  2. Redit集群搭建-Sentinel模式搭建

    Redit集群搭建 学习了: Windows:http://blog.csdn.net/mrxiagc/article/details/52799081 Linux:https://www.cnblo ...

  3. Configuration file schema for the .NET Framework

    https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/index Runtime Settings ...

  4. 如何解读「量子计算应对大数据挑战:中国科大首次实现量子机器学习算法」?——是KNN算法吗?

    作者:知乎用户链接:https://www.zhihu.com/question/29187952/answer/48519630 我居然今天才看到这个问题,天……本专业,有幸听过他们这个实验的组会来 ...

  5. 45.angular路由设置

    转自:https://www.cnblogs.com/best/tag/Angular/ AngularJS 路由也可以通过不同的模板来实现. $routeProvider.when 函数的第一个参数 ...

  6. 36.创建模板mylist

    node.h #pragma once //创建模板 template <class T> class Node { public: T t;//数据 Node *pNext;//指针域 ...

  7. Android项目实战(四十四):浅谈Postman (网络请求调试插件)

    前言: Postman是一款功能强大的网页调试与发送网页HTTP请求的Chrome插件.    在项目开发中,可以依赖此工具模拟API测试. 使用详解: 各种情况Api的模拟请求的Postman使用方 ...

  8. net实现ping的方法

    class ServicePinger { private static readonly ILog log = LogManager.GetLogger(typeof(ServicePinger)) ...

  9. 用@property (copy) NSMutableArray *array;会有什么问题?

    我们县回忆一下copy属性的作用,一个属性标记了copy,当你调用他的setter方法,他会建立一个索引计数为1的对象,然后释放旧对象. @property (copy) NSMutableArray ...

  10. caffe(13) 数据可视化(python接口)配置

    caffe程序是由c++语言写的,本身是不带数据可视化功能的.只能借助其它的库或接口,如opencv, python或matlab.大部分人使用python接口来进行可视化,因为python出了个比较 ...