Hi,
I'm struggling to understand the difference between the following ways returning a model to a view from my controllers:
Code:
Map<String, Object> model = new HashMap<String, Object>();
model.put(key, value);
return new ModelAndView("aview", "model", model);
When I use the above, I have to access the model from my JSP views as follows:
Code:
Value = ${model.key}
I can also use:
Code:
Map<String, Object> model = new HashMap<String, Object>();
model.put(key, value);
ModelAndView mav = new ModelAndView("aview");
mav.getModel().putAll(model);
return mav;
When I use the above, I have to access the model from my JSP views as follows (i.e. model. is not necessary):
Why is this different? I know that in the second example I don't give a name to the model for instance. Does JSP lookup key/values in some sort of 'default' model that gets populated in the second example?
What is the preferred method?
Many thanks,
Nes