当属性名称的第二个字符是大写时抛出 javax.el.PropertyNotFoundException
我有一个不寻常的场景:
我有一个 RegistrationVO,它的属性和 getter setter 很少。 例如 city
或 bCity
及其 getter 方法 getCity()
和 getBCity()
在 JSP 中我尝试显示使用 scriplet 计算这些属性的值, <%=registrationVO.getCity()%>
和 <%=registrationVO.getBCity()%>
,效果很好。 但我用表达语言替换了相同的内容, ${registrationVO.city}
和 ${registrationVO.bCity}
我收到一条错误消息,指出在 RegistrationVO 中未找到属性“bCity”。 ia 再次对 bCity 使用 scriplet,我得到了输出。
我观察到这是因为命名约定。 “如果属性的第二个字符是大写字母,我们就不能使用表达式语言”。我尝试过许多差异命名,这就是我发现的。
请检查一下这个场景,我不知道我的结论是对还是错。
谢谢, DJ
I have this unusual scenario:
I have a registrationVO with few properties and getter setters for that.
For example city
or bCity
with their getter methods getCity()
and getBCity()
In JSP i tried to display the value of these properties using scriplets,<%=registrationVO.getCity()%>
and <%=registrationVO.getBCity()%>
, It works fine.
But i replaced the same with expression language,${registrationVO.city}
and ${registrationVO.bCity}
i got an error saying property "bCity" not found in registrationVO.
i a used scriplet again for bCity, i got the output.
I observed that its because of the naming convention. "If the second character of the property is a Capital letter we cant use Expression Language". I have tried with many diff namings, this is what i found out.
Please check this scenario, I don't know wether my conclusion is right or wrong.
Thanks,
DJ
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果 getter 方法的属性名称至少以两个大写字符开头,那么您也需要在 EL 属性名称中使用所有这些大写字符。在您的特定情况下,您需要将其替换为
${registrationVO.BCity}
。这是在 Javabeans 规范 的第 8.8 章中指定的。这是本章的摘录(重点是我的):也就是说,我宁愿将它们重命名为更合理的名称。也许是
birthCity
(如果我猜对的话),这样你就可以很好地使用${registrationVO.birthCity}
。If the property name of the getter method starts with at least two uppercase characters, then you need to use all of those uppercase characters in the EL property name as well. In your particular case, you need to replace it by
${registrationVO.BCity}
. This is specified in chapter 8.8 of the Javabeans spec. Here's an extract of the chapter (emphasis mine):That said, I would rather rename them to something more sensible. Maybe
birthCity
(if I guess it right), so that you can just nicely use${registrationVO.birthCity}
.