我用的是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]}]]
我想知道这些数据要怎样才能正常显示出来呢?