Getter Property (without property and setter) Acce

2019-06-02 01:15发布

问题:

public class MyAction extends ActionSupport
{
     public String getMyValue()
     {
          return "SomeText";
     }
     ...
}

I have this MyAction class. Now, the question is that when I refer myValue in my JSP page using OGNL, will it create the myValue property on ValueStack, or will it just call the getter method?

回答1:

It will call a getter method. The OGNL when evaluating an expression finding a property accessor corresponding to the name of the property. It's doing it using reflection on the method basis via prefixing "get"/"set" to the name of the property.