gotch4
gotch4

Reputation: 13299

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

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:

Feel free to add resources to clarify my ideas

Upvotes: 7

Views: 6391

Answers (2)

Bozho
Bozho

Reputation: 597342

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.

Upvotes: 0

skaffman
skaffman

Reputation: 403591

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.

Upvotes: 7

Related Questions