还是SpringMVC重定向参数的问题

我用的是SpringMVC 4.2.4。

    @RequestMapping(value = "/test1", method = RequestMethod.POST)
    public String test1(@Validated SysUser sysUser, BindingResult result, RedirectAttributes attr) {
        String url = "redirect:/index.jsp";
        try {
            if (result.hasErrors()) {
                Map<String, String> errors = buileValidatedMessage(result);
                System.out.println(errors);
                attr.addFlashAttribute("errMsg", errors);
                attr.addFlashAttribute("myinfo", "123456789");
                attr.addAttribute("info", 55);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return url;
    }

页面:

    <h2>Hello World!</h2>
    <h3>1.${myinfo}</h3>
    <h3>2.${errMsg}</h3>
    <h3>3.${info}</h3>

这样在页面上没有数据输出,但是在页面上获取session信息:

 <%
    Enumeration<String> names1 = session.getAttributeNames();
    while (names1.hasMoreElements()) {
        String name = names1.nextElement();
        out.println(name + " : " + session.getAttribute(name) + "<br>");
    }
%>

这样就能看到里面的数据:

 org.springframework.web.servlet.support.SessionFlashMapManager.FLASH_MAPS : [FlashMap [attributes={errMsg={fdPassword=密码不能空, fdUsername=用户名不能空;用户名长度必须在3~10个字符之间}, myinfo=123456789}, targetRequestPath=/smart/index.jsp, targetRequestParams={info=[55]}]]

我想知道这些数据要怎样才能正常显示出来呢?

@RequestMapping(value = "/test1", method = RequestMethod.POST)
public ModelAndView test1(@Validated SysUser sysUser, BindingResult result, RedirectAttributes attr) {
String url = "redirect:/index.jsp";
try {
if (result.hasErrors()) {
Map errors = buileValidatedMessage(result);
System.out.println(errors);
attr.addFlashAttribute("errMsg", errors);
attr.addFlashAttribute("myinfo", "123456789");
attr.addAttribute("info", 55);
}
} catch (Exception e) {
e.printStackTrace();
}
return new ModelAndView("redirect:/index.jsp?errMsg="+errors+"&myinfo=123456789&info=55");
}
改为这样写试试

RedirectAttributes,,将参数放到这里面就能重定向到jsp页面了

你可以试试${sessionScope['org.springframework.web.servlet.support.SessionFlashMapManager.FLASH_MAPS'][0][key]}这样的方式
参考博客:http://ljyav8b.blog.163.com/blog/static/269016720167412024479/