gpt4 book ai didi

java - Spring RedirectAttributes 导致 "Cannot create a session after the response has been committed"错误

转载 作者:行者123 更新时间:2023-12-02 07:09:44 25 4
gpt4 key购买 nike

向 Flash map 添加重定向属性会导致以下异常

java.lang.IllegalStateException: Cannot create a session after the response has been committed
at org.apache.catalina.connector.Request.doGetSession(Request.java:2377)
at org.apache.catalina.connector.Request.getSession(Request.java:2097)
at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:833)
at org.springframework.web.servlet.support.DefaultFlashMapManager.retrieveFlashMaps(DefaultFlashMapManager.java:149)
at org.springframework.web.servlet.support.DefaultFlashMapManager.requestCompleted(DefaultFlashMapManager.java:202)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:830)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)

这就是我的请求处理程序的样子

@RequestMapping(value = "/foo", method = RequestMethod.POST)
public String getFoo(RedirectAttributes attr) {
attr.addFlashAttribute("twiddle", "doodle");
return "redirect:/cow";
}

有谁知道导致此问题的原因/如何调试问题?

最佳答案

经过一番调查,发现提供发布到/foo 的表单的 JSP View 具有 session=false 页面指令属性,如下所示:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"  session="false" %>

Spring 重定向属性使用 HttpSession 对象,该属性会导致跳过 HttpSession 生成。删除该属性/将其设置为 true 后,重定向工作正常

关于java - Spring RedirectAttributes 导致 "Cannot create a session after the response has been committed"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15671793/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com