如何在 JSP 中创建对象并使用 EL/JSTL 访问它?

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

我在 JSP 文件中创建了一个对象,如下所示

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

稍后我需要像下面这样在我的标签中访问它

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

奇怪的是我无法访问客户端中的对象,即c1.sa

请注意 c1.sa.getBalance() 在我的 eclipse 测试驱动程序中运行

我目前正在使用如下所示的丑陋解决方案

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

并使用

访问它
${pageScope.at.getName()}
${pageScope.sa.getBalance()}

如果有更好的方法请指教