加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 在JSP中仅为特定的属性王使用表达式语言时出现异常错误

发布时间:2020-12-15 08:32:08 所属栏目:Java 来源:网络整理
导读:我有这种不寻常的情况: 我有一个registrationVO,它有很少的属性和getter setter. 例如city或bCity及其getter方法getCity()和getBCity() 在JSP中,我尝试使用scriplets显示这些属性的值, %= registrationVO.getCity()%和%= registrationVO.getBCity()%,它
我有这种不寻常的情况:

我有一个registrationVO,它有很少的属性和getter setter.
例如city或bCity及其getter方法getCity()和getBCity()

在JSP中,我尝试使用scriplets显示这些属性的值,
<%= registrationVO.getCity()%>和<%= registrationVO.getBCity()%>,它工作正常.
但我用表达语言替换了相同的,
${registrationVO.city}和${registrationVO.bCity}
我得到一个错误,说在注册中没有找到属性“bCity”.
我再次使用了一个用于bCity的scriplet,我得到了输出.

我观察它是因为命名惯例. “如果财产的第二个字符是大写字母,我们就不能使用表达语言”.我试过很多差异,这就是我发现的.

请检查这个场景,我不知道我的结论是对还是错.

谢谢,
DJ

解决方法

如果getter方法的属性名称以至少两个大写字符开头,那么您还需要在EL属性名称中使用所有这些大写字符.在您的特定情况下,您需要用${registrationVO.BCity}替换它.这在 Javabeans spec的第8.8章中有详细说明.这是本章的摘录(强调我的):

8.8 Capitalization of inferred names.

When we use design patterns to infer a property or event name,we need to decide what rules
to follow for capitalizing the inferred name. If we extract the name from the middle of a normal
mixedCase style Java name then the name will,by default,begin with a capital letter.

Java programmers are accustomed to having normal identifiers start with lower case letters.
Vigorous reviewer input has convinced us that we should follow this same conventional rule
for property and event names.

Thus when we extract a property or event name from the middle of an existing Java name,we
normally convert the first character to lower case. However to support the occasional use of all
upper-case names,we check if the first two characters of the name are both upper case and if
so leave it alone
. So for example,

  • “FooBah” becomes “fooBah”
  • “Z” becomes “z”
  • “URL” becomes “URL”

We provide a method Introspector.decapitalize which implements this conversion rule.

也就是说,我宁愿将它们重命名为更合理的东西.也许是BirthCity(如果我猜对了),那么你可以很好地使用${registrationVO.birthCity}.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读