Reputation: 41
I'm trying to send data to jsp but its not working
public class LoginPageController extends SimpleFormController
{
public ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors)
throws ServletException
{
Loginpage lcmd=(Loginpage)command;
System.out.println("This is LOGIN PAGE");
System.out.println(lcmd.getUserName());
System.out.println(lcmd.getPassWord());
request.setAttribute("MSG","Thank u"); //This code not doing anything.
return new ModelAndView(new RedirectView("Login.jlc"));
}
}
Upvotes: 2
Views: 5348
Reputation: 135862
You are changing the request
object, that will indeed do nothing.
What you want is add a variable to the Model. So here's how you can do it:
Instead of:
request.setAttribute("MSG","Thank u"); //This code not doing anything.
return new ModelAndView(new RedirectView("Login.jlc"));
Try this:
Map<String, Object> model = new HashMap<String, Object>();
model.put("MSG", "Thank u");
return new ModelAndView(new RedirectView("Login.jlc"), model); // <-- notice this
This will enable you to access that "Thank u"
value through the expression ${model.MSG}
and others, if you add them to the model
map.
Upvotes: 1