0

I came across the following code:

<c:set var="list value="${actionBean.ABC}"> in a JSP file.

Then I found it is calling the following method in one of the Java files:

List<...> getABC(...){}

I cannot find another binding annotation, or routing in config files about ABC. My question is how does EL knows to call this method? is the "get" automatically be appended during some kind of method naming conversion mechanisim behind the scene?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
shole
  • 4,046
  • 2
  • 29
  • 69

1 Answers1

0

This's not JSP-specific behavior. JSP uses JavaBeans to access methods & properties. Here is how JavaBeans lookup a property JavaBeans Specification § 8.3.1:

By default, we use design patterns to locate properties by looking for methods of the form:

public <PropertyType> get<PropertyName>();

public void set<PropertyName>(<PropertyType> a);

If we discover a matching pair of “get<PropertyName>” and “set<PropertyName>” methods that take and return the same type, then we regard these methods as defining a read-write property whose name will be “<propertyName>”. We will use the “get<PropertyName>” method to get the property value and the “set<PropertyName>” method to set the property value. The pair of methods may be located either in the same class or one may be in a base class and the other may be in a derived class.

If we find only one of these methods, then we regard it as defining either a read-only or a write-only property called “<propertyName>” By default we assume that properties are neither bound nor constrained (see Section 7).

So a simple read-write property “foo” might be represented by a pair of methods:

public Wombat getFoo();

public void setFoo(Wombat w);
Al-Anazi
  • 364
  • 1
  • 8
  • I am still investigating but I suspect it is specified in Stripes framework ( a lightweight version of Structs), but not so sure – shole Dec 19 '22 at 05:46
  • @shole as if you are saying that JSP will teach you how to use double or int. As JSP expects that you know Java, these frameworks probably will assume that you know JSP basics. – Al-Anazi Dec 19 '22 at 06:35