0

I have a method in my controller say demo

@RequestMapping(value="/demo")
public ModelAndView demo("some parameters..")
{
 .
 .
 .
 .
 return new ModelAndView("newPage","Message","Welcome to new Page");
{

This will send the data to the "newPage". now my question is, can I send the same data to one more page? Does ModelAndView allows it? Every Advice is Appreciated.

Himanshu Arya
  • 75
  • 1
  • 9
  • Yes you can use session.setAttribute("yourKaye",yourData); and use session.getAttribute("yourKey"); to get on any jsp page. – Sudhir Ojha Oct 09 '18 at 11:01
  • @Sudhir Ojha Thanks for the help, Your solution will work but it will require me to write Java code on jsp page which I Can't do. Can you suggest me a solution using ModelAndView? – Himanshu Arya Oct 09 '18 at 11:11

1 Answers1

0

ModelAndView pass data to Page scope. So Model And View can't send data to other pages. So you should use Session scope or Application scope to pass data to other pages.

Session -> session.setAttribute("key",data);

Application -> context.setAttribute("key",data);

Servlet Scopes

Sudhir Ojha
  • 3,247
  • 3
  • 14
  • 24