Leon Armstrong
Leon Armstrong

Reputation: 1303

How to create object in JSP and access it using EL/JSTL?

I am having an object created in JSP file like below

<%
Client c1= new Client(dbc,id);
pageContext.setAttribute("c1", c1 );
%>

And later on I need to access it in my tag like below

<t:client_layout title="">
<jsp:attribute name="content">
.....
${pageScope.c1.getFirstName()}//working
${pageScope.c1.sa.getBalance()}//not working!
.....
</jsp:attribute>
</t:client_layout>

The weird part is I am not able to access the object inside client which is c1.sa

Please note the c1.sa.getBalance() is working inside my eclipse testdriver

Upvotes: 2

Views: 3225

Answers (1)

Leon Armstrong
Leon Armstrong

Reputation: 1303

I am currently using a ugly solution like below

Client c1= new Client(dbc,id);
pageContext.setAttribute("c1", c1 );
pageContext.setAttribute("sa", c1.sa );
pageContext.setAttribute("at", c1.sa.at );

And access it using

${pageScope.at.getName()}
${pageScope.sa.getBalance()}

Please advice if there are better ways to do this.

Upvotes: 1

Related Questions