通过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

查看:149
本文介绍了通过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类型的对象,而不是String,它从异常中将其视为String对象.我在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或我必须使用scriptlet/表达式?

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

谢谢, 阿尔玛斯

推荐答案

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

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天全站免登陆