7

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

skaffman
  • 398,947
  • 96
  • 818
  • 769
gotch4
  • 13,093
  • 29
  • 107
  • 170

2 Answers2

7

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.

skaffman
  • 398,947
  • 96
  • 818
  • 769
0

They are usually stored in the request. So request.getAttributeNames() should give you all your model (but use that only for educational purposes - otherwise use EL to access the model). That said, it should also be accessible from the pageContext (in request scope).

And yes, it is automatically added.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140