I have some classes which extends a superclass, and in the JSP I want to show some attributes of these classes. I only want to make one JSP, but I don\'t know in advance if the
Just a more detailed (typical?) usage of BalusC great answer
<%--
[1] sets a default value for variable "currentAttribute"
[2] check if myObject is not null
[3] sets variable "currentAttribute" to the value of what it contains
[4] catches "property not found exception" if any
- if exception thrown, it does not output anything
- if not exception thrown, it outputs the value of myObject.myAttribute
--%>
<%-- [1] --%>
<%-- [2] --%>
<%-- [3] --%>
${myObject.myAttribute} <%-- [4] --%>
<%-- use the "currentAttribute" variable without worry in the rest of the code --%>
currentAttribute is now equal to: ${currentAttribute}
As pointed out by Shervin in the comments of BalusC's answer, this is probably NOT the cleanest solution but as replied by BalusC "that's so far the only way to achieve the odd requirement".
Resources