我在 Linux 上运行 Tomcat 6.0.18。
我有一个使用这样的 bean 的 JSP:
<jsp:useBean id="helper"
type="com.example.SomeType"
scope="request"/>
helper
该页面使用如下表达式语言引用 的属性:
<!-- This works properly, but could fail silently if the bean name is incorrect. -->
<div><p>Here's some stuff: ${helper.stuff}</div>
在一些我错过了 name 的重构过程中helper
,我注意到如果 name写入不正确,不会引发错误。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>
现在,如果我使用以下 JSP 语法且名称不正确,则会引发错误(显示我的自定义错误页面,并且我在日志文件中看到异常)helper
:
<!-- Wrong name, but an error is raised. -->
<div><p>Here's some stuff: <jsp:getProperty name="foo" property="stuff"/></div>
在这种情况下,日志会记录以下条目:
SEVERE: requestURI: /some.jsp servletName: jsp statusCode: 500
org.apache.jasper.JasperException: Attempted a bean operation on a null object.
为了完整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>
为什么我在编写 ${foo.stuff} 时没有看到错误?在这种情况下是否有一些配置选项可以控制错误报告?