用 JSP 编写:
${a.b.c}
抛出“c”PropertyNotFound,但写
<s:property value="#a.b.c"/>
工作正常。
如果有人能解释原因,我将不胜感激
${a.b.c}
不起作用?更新:
在同一个 JSP 中,访问另一个 bean
f
如 ${a.f.d}
它找到 d
正确。我已经检查了该属性
c
在 ${a.b.c}
存在。
最佳答案
好问题。如果您没有为 b 中的属性 c 指定 getter setter,那么将发生此错误 Propertynotfound
为了
${a.b.c}
但
<s:property value="#a.b.c"/>
不会导致错误。不同之处在于 ${} 适用于 getter setter,因为它是 OGNL,它使用 valuestack 中的 getter setter 读取。
只需在 b 类中编写 getter setter。 ${a.b.c} 将开始工作。例如,如果 c 是 public String c 那么,
public String getC() {
return c;
}
public void setC(String c) {
this.c = c;
}
关于jsp - 为什么jsp会触发PropertyNotFound?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21874470/