Search code examples
jspsyntaxstruts2elognl

why jsp fires a PropertyNotFound?


Writing in a JSP:

${a.b.c} 

throws 'c' PropertyNotFound, but writing

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

works fine.

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

UPDATED:

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

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


Solution

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

     ${a.b.c}
    

    But

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

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

    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;
    }