所以我在 jsp 文件中有这个简单的代码:
${requestScope.getClass()}
返回我:
class javax.servlet.jsp.el.ImplicitObjectELResolver$ScopeManager$9
这让我认为这个对象是 ImplicitObjectELResolver 类型。 (即使在这里我也可能是错的..)
好吧,当我查看文档 here 时对于这个不错的类:javax.servlet.jsp.el.ImplicitObjectELResolver ,我明白了:
Defines variable resolution behavior for the EL implicit objects defined in the JSP specification.
The following variables are resolved by this ELResolver, as per the JSP specification:
pageContext - the PageContext object. pageScope - a Map that maps page-scoped attribute names to their values.
requestScope - a Map that maps request-scoped attribute names to their values.
现在我很困惑,因为我认为我已经拥有 Map 类型的对象。但我拥有的对象应该有一个名为 requestScope 的变量,它是一个 Map..
那么当我打电话时实际发生了什么
${requestScope.firstName}
例如?
我是在 Map 对象上调用 getKey("firstName") ,还是发生了其他事情?
最佳答案
作为 EL 解析的一部分,JSP servlet 将使用 ImplicitObjectELResolver
解析名称requestScope
。该决议包括调用getRequestScopeMap()
它返回类型为 EnumeratedMap<String, Object>
的匿名内部类它可以访问请求范围内的所有属性。
一旦EnumeratedMap
返回后,EL 解析将继续尝试调用 Map
的get(..)
EL 表达式中具有给定名称的方法。例如,名称为firstName
在
${requestScope.firstName}
不同版本的实现可能有所不同。
关于java - 表达式语言的 requestScope 对象如何在 JSP 文件中工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24683480/