通过 jsp:param 传递的对象抛出 javax.el.PropertyNotFoundException: Property 'foo'在 java.lang.String 类型上找不到

发布于 2024-10-06 23:23:39 字数 1260 浏览 4 评论 0原文

我知道这可能是一个愚蠢的问题,我尝试谷歌搜索但没有得到完美的答案。

我正在使用以下代码

<c:forEach var="aggregatedBatchProgressMetrics" items="${batchProgressMetricsList}">  
    <jsp:include page="html/tableContentsDisplayer.jsp">  
        <jsp:param name="batchProgressMetrics" value="${aggregatedBatchProgressMetrics}" />
    </jsp:include>
</c:forEach>  

并在 html/tableContentsDisplayer.jsp 中,我

<c:set var="aggregatedBatchProgressMetrics">${param.batchProgressMetrics}</c:set>    
    <tr>  
        <td class="tdcenter">${aggregatedBatchProgressMetrics["clientId"]}</td>    
        <td class="tdcenter">${aggregatedBatchProgressMetrics["instrumentStats"]["totalImntsCompleted"]}</td>  
        <td class="tdcenter">${aggregatedBatchProgressMetrics["instrumentStats"]["totalImntsRemaining"]}</td>
    </tr>  

从 c:forEach 得到以下的aggregateBatchProgressMetrics 是 com.xyz.AggreeratedBatchProgressMetrics 类型的对象,而不是字符串,从例外情况来看,它将其视为字符串对象。我在 bean 中有 getClientId 方法。另外,如果我按原样放置包含的 jsp 文件的内容(没有指令和 c:set 标记),它绝对可以正常工作。有没有一种方法可以使用 jsp:param 标记传递对象,并在接收端将其作为对象获取?

是否可以使用 jstl 或者我必须使用 scriptlet/expression 来实现相同的目的?

谢谢, 阿尔马斯

I know this might be silly question and i tried googling but didnt got perfect answer.

I am using following code

<c:forEach var="aggregatedBatchProgressMetrics" items="${batchProgressMetricsList}">  
    <jsp:include page="html/tableContentsDisplayer.jsp">  
        <jsp:param name="batchProgressMetrics" value="${aggregatedBatchProgressMetrics}" />
    </jsp:include>
</c:forEach>  

and inside html/tableContentsDisplayer.jsp, i have following

<c:set var="aggregatedBatchProgressMetrics">${param.batchProgressMetrics}</c:set>    
    <tr>  
        <td class="tdcenter">${aggregatedBatchProgressMetrics["clientId"]}</td>    
        <td class="tdcenter">${aggregatedBatchProgressMetrics["instrumentStats"]["totalImntsCompleted"]}</td>  
        <td class="tdcenter">${aggregatedBatchProgressMetrics["instrumentStats"]["totalImntsRemaining"]}</td>
    </tr>  

aggregatedBatchProgressMetrics is what i get from c:forEach is an object of type com.xyz.AggregatedBatchProgressMetrics and not a String, from the exception it treats that as an String object. I have getClientId method inside the bean. Also if i place the content of included jsp file as is (without directives and c:set tag) it works absolutely fine. Is there a way i can pass an object using jsp:param tag and on the recieving end i get it as an object?

Is it possible using jstl or i will have to use scriptlets/expression for the same?

Thanks,
Almas

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黯淡〆 2024-10-13 23:23:39

HTTP 请求参数被视为字符串。对于 jsp:param 来说,它基本上是通过 String#valueOf() 转换为字符串的。而是在 的帮助下将其作为对象存储在请求范围中。

<c:forEach var="aggregatedBatchProgressMetrics" items="${batchProgressMetricsList}">  
    <c:set var="batchProgressMetrics" value="${aggregatedBatchProgressMetrics}" scope="request" />
    <jsp:include page="html/tableContentsDisplayer.jsp" />  
</c:forEach>

<tr>  
    <td class="tdcenter">${batchProgressMetrics["clientId"]}</td>    
    <td class="tdcenter">${batchProgressMetrics["instrumentStats"]["totalImntsCompleted"]}</td>  
    <td class="tdcenter">${batchProgressMetrics["instrumentStats"]["totalImntsRemaining"]}</td>
</tr>  

HTTP request parameters are treated as strings. With jsp:param it's basically been converted to string by String#valueOf(). Rather store it as object in the request scope with help of <c:set>.

<c:forEach var="aggregatedBatchProgressMetrics" items="${batchProgressMetricsList}">  
    <c:set var="batchProgressMetrics" value="${aggregatedBatchProgressMetrics}" scope="request" />
    <jsp:include page="html/tableContentsDisplayer.jsp" />  
</c:forEach>

<tr>  
    <td class="tdcenter">${batchProgressMetrics["clientId"]}</td>    
    <td class="tdcenter">${batchProgressMetrics["instrumentStats"]["totalImntsCompleted"]}</td>  
    <td class="tdcenter">${batchProgressMetrics["instrumentStats"]["totalImntsRemaining"]}</td>
</tr>  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文