Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does the Spring Model that is passed to a JSP goes to?

Tags:

spring-mvc

jsp

I've been reading docs and tutorials about spring (3.0), so I've learnt how to return a ModelAndView with the JSP name and a Map as the model. I've learnt also that in a JSP, if you want to access one key of that map you do ${attributename} and so on. That's JSP EL. Now my questions:

  • What object of the page is the EL accessing? Is that PageContext? I tried to find those keys in PageContext.getAttribute but they are not there.
  • Whatever the object is, is it automatic that the things in the model go there?

Feel free to add resources to clarify my ideas

like image 895
gotch4 Avatar asked Dec 14 '10 16:12

gotch4


1 Answers

When you do something like ${attributename}, JSP EL will check a variety of sources to find it, including the page and request contexts (in that order).

When your Spring controller returns a model (e.g. inside the ModelAndView), this model is decomposed by Spring's AbstractView class and inserted into the request context (this is the "magic" part), so that when your JSP EL expression refers to an item from the model, it's available to be used.

like image 93
skaffman Avatar answered Oct 14 '22 08:10

skaffman