传递给JSP的Spring模型去哪里了? [英] Where does the Spring Model that is passed to a JSP goes to?

查看:82
本文介绍了传递给JSP的Spring模型去哪里了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读有关spring(3.0)的文档和教程,因此,我学习了如何返回具有JSP名称和Map作为模型的ModelAndView.我还了解到,在JSP中,如果要访问该映射的一个键,请执行${attributename}等等.那就是JSP EL.现在我的问题:

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:

  • EL正在访问页面的哪个对象?是PageContext吗?我试图在PageContext.getAttribute中找到这些键,但是它们不在那里.
  • 无论对象是什么,模型中的东西都自动到达那里吗?
  • 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

推荐答案

当您执行类似${attributename}的操作时,JSP EL将检查各种源以找到它,包括页面和请求上下文(按此顺序).

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).

当Spring控制器返回一个模型(例如,在ModelAndView内部)时,该模型由Spring的AbstractView类分解,并插入到请求上下文中(这是魔术"部分),以便当您的JSP EL表达式是指模型中的一项,可以使用.

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.

这篇关于传递给JSP的Spring模型去哪里了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆