diypyh 2016-01-06 03:44 采纳率: 16.7%
浏览 1898

还是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]}]]

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

  • 写回答

3条回答 默认 最新

  • zhchengda 2016-01-06 04:40
    关注

    @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");
    }
    改为这样写试试

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器