为什么jsp会触发PropertyNotFound? [英] why jsp fires a PropertyNotFound?

查看:121
本文介绍了为什么jsp会触发PropertyNotFound?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JSP中编写:

${a.b.c} 

抛出"c" PropertyNotFound,但写出

throws 'c' PropertyNotFound, but writing

<s:property value="#a.b.c"/> 

正常工作.

如果有人能解释为什么${a.b.c}无效的话,我将不胜感激.

I'd appreciate if someone can explain why ${a.b.c} doesn't work?

已更新:

在同一JSP中,访问另一个Bean f(例如${a.f.d})可以正确找到d.

In the same JSP, accessing to another bean f such as ${a.f.d} it finds d correctly.

我检查了${a.b.c}中的属性c是否存在.

I have checked that property c in ${a.b.c} exists.

推荐答案

好问题.如果您尚未为b中的属性c指定getter设置方法,则此错误将在

Nice Question.If you have not specified getter setters for property c in b then this error will occur Propertynotfound for

 ${a.b.c}

但是

  <s:property value="#a.b.c"/> 

不会导致错误.区别在于$ {}适用于getter设置程序,因为它是OGNL,它是使用valuestack中的getter设置程序读取的.

will not cause an error. The difference is ${} works on getter setters as it is OGNL it reads using getter setter from valuestack.

只需在类b中编写getter setter. $ {a.b.c}将开始工作.例如,如果c是公共字符串c,则

Simply write getter setter in class b. ${a.b.c} will start working. For example if c is public String c then,

public String getC() {
    return c;
}
public void setC(String c) {
    this.c = c;
}

这篇关于为什么jsp会触发PropertyNotFound?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆