I want to pass values to the redirected operation. i.e in my below code I want to pass userResult value to the method welcome, how can I pass it?
String userResult = getUserDetails(url);
System.out.println("Result-->"+userResult);
if(userResult.contains("<user>")){
return "redirect:welcome";
}
redirected code:
@RequestMapping(value = "/welcome")
public String welcome(Model model){
Element element = getOutputDetails(userResult);// get userResult values here
If you use spring 3.1 or above, have a look at Spring MVC Flash Attribute
The feature is used to pass values between handler methods in redirect situations.
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
//...
@RequestMapping...
public String login(@ModelAttribute....,
final RedirectAttributes redirectAttributes) {
String userResult = getUserDetails(url);
System.out.println("Result-->"+userResult);
if(userResult.contains("<user>")){
redirectAttributes.addFlashAttribute("userResult", userResult);
return "redirect:welcome";
}
......
}
@RequestMapping(value = "/welcome")
public String welcome((@ModelAttribute("userResult") String userResult){
......
}