Search code examples
jstlencapsulation

JSTL violating Encapsulation


JSTL tags in .jsp can violate encapsulation just like that:

< jsp:getProperty property="aPrivateID" name="someObj" />

gets the value of the variable "aPrivateID" declared as "private" in "someObj".

Isn't this a bit odd?

Is/n't there a way to control it and stop JSTL having access to private members of objects?


Solution

  • Your example JSP doesn't get the value of the private variable aPrivateID. Instead that JSP calls a public accessor method named getAPrivateID() and returns the result. Encapsulation is preserved.