Tuesday, 1 October 2013

Maintain data in redirection between different URLs in spring controller

Maintain data in redirection between different URLs in spring controller

I have just started to learn Spring MVC. So, sorry if my beginner level
irritates you.
To have my question short and clear i am using following simple code example.
i have two functions in two different spring MVC controllers. In first
controller, i am having:
@RequestMapping("/first")
public String first(Model model){
model.addAttribute("user", "User Name");
return "redirect:/second";
}
In second controller i am having:
@RequestMapping("/second")
public String second(){
return "myView";
}
Actually the first is redirecting to the second. Bt in my view(html), when
i try to get model's value like:
<h1>Welcome! ${user} <h1> //code in html to get user object
It shows empty.
So my question is how to transfer data when you are redirecting between
two requests in spring MVC. what is the best solution to achieve this. Can
i achieve this by Model or some other approach is there...? Thanks in
advance

No comments:

Post a Comment