I have a doubt about Model behavior in Spring MVC.
I have a controller class with to handler methods, say:
@RequestMapping(value = "/result", method = RequestMethod.GET)
public String getExportResults(@RequestParam("token") String token,
Model model) {
// ...
model.addAttribute("task", myObject);
// ...
}
@RequestMapping(value = "/file", method = RequestMethod.GET)
public void getFile(Model model, HttpServletResponse response)
// can't find "task" attribute...
}
When I put the "task" attribute into model, in my getExportResults I expect to find it into model argument of getFile method, but when I try to get it, "task" is null.
Am I wrong? Maybe model behaviour is not clear to me…
Your expectations are wrong. Putting something in the model makes it available for the current request only. The goal of adding something into the model is to make it available for the view, in order to generate the HTML page.