通过 jsp:param 传递的对象抛出 javax.el.PropertyNotFoundException: 在类型 java.lang.String 上找不到属性“foo" [英] Object passed via jsp:param throws javax.el.PropertyNotFoundException: Property 'foo' not found on type java.lang.String

查看:32
本文介绍了通过 jsp:param 传递的对象抛出 javax.el.PropertyNotFoundException: 在类型 java.lang.String 上找不到属性“foo"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我正在使用以下代码

<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 中,我有以下内容

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 是我从 c:forEach 中得到的,它是一个 com.xyz.AggregatedBatchProgressMetrics 类型的对象,而不是一个字符串,例外是它把它当作一个字符串对象.我在 bean 中有 getClientId 方法.此外,如果我按原样放置包含的 jsp 文件的内容(没有指令和 c:set 标记),它绝对可以正常工作.有没有办法我可以使用 jsp:param 标签传递一个对象,然后在接收端我把它作为一个对象?

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?

是否可以使用 jstl 或者我将不得不使用 scriptlets/expression 来实现?

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

谢谢,阿尔玛斯

推荐答案

HTTP 请求参数被视为字符串.使用jsp:param,它基本上被String#valueOf() 转换为字符串.而是在 的帮助下将其作为对象存储在请求范围内.

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>  

这篇关于通过 jsp:param 传递的对象抛出 javax.el.PropertyNotFoundException: 在类型 java.lang.String 上找不到属性“foo"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆