Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SpringMVC3.1中的Flash属性对重定向的JSP不可见_Spring_Redirect_Spring Mvc_Post Redirect Get - Fatal编程技术网

SpringMVC3.1中的Flash属性对重定向的JSP不可见

SpringMVC3.1中的Flash属性对重定向的JSP不可见,spring,redirect,spring-mvc,post-redirect-get,Spring,Redirect,Spring Mvc,Post Redirect Get,我使用Spring3.1的新Flash属性支持在控制器中的RedirectAttributes对象上设置Flash属性,然后调用重定向。该重定向请求依次被过滤器捕获,然后过滤器将其快速发送到它的目标JSP。问题是:我无法从过滤器的doFilter()方法或JSP中看到flash属性。非flash(URL)属性使它很好 执行重定向的控制器: @RequestMapping("/pages/login") public String login (HttpServletRequest request

我使用Spring3.1的新Flash属性支持在控制器中的
RedirectAttributes
对象上设置Flash属性,然后调用重定向。该重定向请求依次被过滤器捕获,然后过滤器将其快速发送到它的目标JSP。问题是:我无法从过滤器的
doFilter()
方法或JSP中看到flash属性。非flash(URL)属性使它很好

执行重定向的控制器:

@RequestMapping("/pages/login")
public String login (HttpServletRequest request, Map<String, Object> model, RedirectAttributes redirectAttributes) {
    model.put("userId", "batman");
    String redirectUrl = request.getParameter("redirectUrl");
    if (redirectUrl != null) {
        redirectAttributes.addAttribute("attr1","ababab");
        redirectAttributes.addFlashAttribute("flashAttr1", "flashflash");
        for (Iterator<String> iterator = model.keySet().iterator(); iterator.hasNext();) {
            String key = iterator.next();
            redirectAttributes.addFlashAttribute(key, model.get(key));
        }
        return "redirect:"+redirectUrl;
    } else {
        return "pages/login";
    }
}
重定向到以下筛选器的页面:

...
<title>Test Web App 1</title>
</head>
<body>
<p>Flash attribute: <c:out value="${flashAttr1}"/></p>
<p>Welcome <c:out value="${userId}"/>!</p>
</body>
</html>
在上面显示的过滤器处短暂停留后,我被带到带有URL的页面

http://my_hostname:8080/test-webapp-1/protected/protected_page.jsp?attr1=ababab
但是我希望JSP能够找到的属性都没有显示出来。我还通过上面显示的
doFilter()
方法进行了调试,但在请求的会话中找不到flash属性


我不确定现在到底出了什么问题。除了那些flash属性外,一切都正常工作。如果还有什么我应该提供的,以使情况更清楚,我将很乐意提供。

几个月前遇到了这个问题,与AJAX相关的重定向。如果使用只读HTTP POST模式,则可以指定一个来模拟POST。还要确保方法返回
视图
模型和视图
(与
字符串
)以便Spring知道查找给定
@RequestMapping
的闪存范围

伪代码:

@RequestMapping(...)
@ResponseStatus(OK)
public ModelAndView login (...) {
    ...
}

当然,我已经设置了
属性(以及不将模型属性设置为URL参数的属性):-)您可以删除过滤器并查看吗?仔细考虑后,我相信问题的核心是因为这里确实涉及重定向,这意味着有两个HTTP会话在起作用。自然地,向一个添加属性对另一个没有影响。因此,实际上没有任何方法可以“修复”这种方法本身;相反,我必须考虑另一种方法,将属性从控制器转移到另一个域中的页面,而不是通过URL查询参数……阅读以下内容:
http://my_hostname:8080/test-webapp-1/protected/protected_page.jsp?attr1=ababab
@RequestMapping(...)
@ResponseStatus(OK)
public ModelAndView login (...) {
    ...
}