我在Linux上运行Tomcat 6.0.18.
我有一个使用这样的bean的JSP:
<jsp:useBean id="helper"
type="com.example.SomeType"
scope="request"/>
Run Code Online (Sandbox Code Playgroud)
该页面引用helper了表达式语言的属性,如下所示:
<!-- This works properly, but could fail silently if the bean name is incorrect. -->
<div><p>Here's some stuff: ${helper.stuff}</div>
Run Code Online (Sandbox Code Playgroud)
在一些我错过了名称出现的重构期间helper,我注意到如果名称写得不正确,则不会引发helper错误.不在屏幕上,而不在我的日志文件中.在输出中没有为表达式语言片段生成任何内容:
<!-- Wrong name! "foo" should be "helper" but no error is observed (other than missing ouput)! -->
<div><p>Here's some stuff: ${foo.stuff}</div>
Run Code Online (Sandbox Code Playgroud)
现在,如果我使用以下具有不正确名称的JSP语法,则会引发错误(我的自定义错误页面显示,我在日志文件中看到异常)helper:
<!-- Wrong name, but an error is raised. -->
<div><p>Here's some stuff: <jsp:getProperty name="foo" property="stuff"/></div>
Run Code Online (Sandbox Code Playgroud)
在这种情况下,日志记录此条目:
SEVERE: requestURI: /some.jsp servletName: jsp statusCode: 500
org.apache.jasper.JasperException: Attempted a bean operation on a null object.
Run Code Online (Sandbox Code Playgroud)
为了完整性,jsp:getProperty当bean名称正确时,语法正常工作:
<!-- Works properly, protects me from an incorrect name, but is more verbose than EL. -->
<div><p>Here's some stuff: <jsp:getProperty name="helper" property="stuff"/></div>
Run Code Online (Sandbox Code Playgroud)
当我写$ {foo.stuff}时,为什么我没有看到错误?在这种情况下是否有一些控制错误报告的配置选项?
表达式语言规范版本2.1的第1.6节中介绍了此行为.
要评估expr-a [expr-b]:
如果value-a为null:
- 如果expr-a [expr-b]是要解析的最后一个属性:
- 如果表达式是值表达式并且调用了ValueExpression.getValue(context)来启动此表达式求值,则返回null.
- 否则,抛出PropertyNotFoundException.试图为左值取消引用null
- 否则,返回null.
(EL统一.和[]运算符)
| 归档时间: |
|
| 查看次数: |
1752 次 |
| 最近记录: |