0

I need show a "message" after redirect with modelAndView but, as is well known, it not possible, then, I use redirectView, but i dont know how show a view. In summary, i need transform this:

ModelAndView model = new ModelAndView("product/edit");

in

RedirectView redirectView = new RedirectView("product/edit");

dnelson
  • 467
  • 1
  • 4
  • 16
davidad
  • 137
  • 1
  • 10

1 Answers1

0

You can store message as session scope attribute and then redirect to jsp page where you can access it back using JSP Standard Tag Library and Expression language.

Controller:

@RequestMapping(...)
public String method1(...){
    ...
    session.setAttribute("message", "Hello, How are you?");
    return "redirect:product/edit";
}

Note: Here you can use RedirectView as well.

JSP:

${sessionScope.message}
Community
  • 1
  • 1
Braj
  • 46,415
  • 5
  • 60
  • 76
  • `return "redirect:product/edit";` is not valid. `product/edit` is a tiles-definitions – davidad Jul 21 '14 at 22:27
  • OK then use with `RedirectView` view but the concept is same. store the message in session attribute. – Braj Jul 21 '14 at 22:28
  • But if I use `RedirectView`, the constructor is only with a URL not with a view – davidad Jul 21 '14 at 22:33
  • Sorry I can't help you in that case. I have posted it from my working project. `redirect:product/edit` works. try some other options as well. What have you defined in configuration? – Braj Jul 21 '14 at 22:35
  • in servlet.xml i have define one resources ``, two bean ´` and `` and the ´tiles.xml´ have this structure: ´/views/product/tiles.xml´ – davidad Jul 21 '14 at 22:48