Human Being
Human Being

Reputation: 8387

Where do model attributes get stored?

I searched a lot and can't find an answer.

Where the model object values are stored in Spring .

Where the model.addAttributes("key","values") values are stored (eg : session , request).What is the scope of the this?

How I can get the values of the stored value in the JSP using the expression language like ${key} ?

How the EL works to retrieve the stored values in the model?

Upvotes: 7

Views: 2562

Answers (2)

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 280138

The DispatcherServlet, which is the entry point of any Spring MVC application, creates a new ModelAndViewContainer object on each request. The javadoc for this class states

Records model and view related decisions made by HandlerMethodArgumentResolvers and HandlerMethodReturnValueHandlers during the course of invocation of a controller method.

Those two interfaces are what handles resolving your @RequestMapping annotated method arguments and return values.

So, during the lifecycle of the request, the model attributes are stored in a ModelMap field of this ModelAndViewContainer object. The actual, current, implementation is a BindingAwareModelMap.

Towards the end of the request, when a view needs to be rendered, some View objects will merge the model attributes with the HttpServletRequest attributes.

How the EL works to retrieve the stored values in the model?

It doesn't. EL resolves the attributes from the JSP's page scope,HttpServletRequest, HttpSession, or ServletContext.

Upvotes: 4

Pradeep Kr Kaushal
Pradeep Kr Kaushal

Reputation: 1546

It's in the request, unless modified with a @SessionAttributes. If you're doing a redirect--request attributes are lost; it's a new request.
For your second and third question are addressed by this link Where does the Spring Model that is passed to a JSP goes to?

Upvotes: 3

Related Questions