将param从一个jsp传递到另一个jsp时出错[重复](error in passing param from one jsp to another [duplicate])

编程入门 行业动态 更新时间:2024-10-25 00:30:39
将param从一个jsp传递到另一个jsp时出错[重复](error in passing param from one jsp to another [duplicate])

这个问题在这里已有答案:

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

我有一个像以下的jsp

<c:forEach items="${brand.weeklyOffers}" var="weeklyOffer"> <jsp:include page="offer.jsp"> <jsp:param name="offer" value="${weeklyOffer}" /> </jsp:include> </c:forEach>

我的提议jsp看起来像followig

<c:set var="offer" value="${param.offer}"/> <div class="accordion-group"> <div class="accordion-heading"> <a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion2" href="#collapse${param.offer.offerId}"><b>${offer.header}</b></a> </div>

抛出以下异常

Caused by: javax.el.PropertyNotFoundException: Property 'offerId' not found on type java.lang.String

但当我这样做

<c:out value="${param.offer}"/>

在offer.jsp中,我可以看到以下结果。

Offer [offerId=ec431f30-9c77-11e3-b3db-3c970e02b4ec, offerImages=[/offer-images/ec431f30-9c77-11e3-b3db-3c970e02b4ec/ec43e280-9c77-11e3-b3db-3c970e02b4ec.jpg], offerDescription=sasa, header=Buy 2 get 1 free, startDate=Sun Feb 16 00:00:00 CET 2014, endDate=Sat Feb 22 00:00:00 CET 2014, city=Munich, worldwide=false, iso8601StartDate=2014-02-16T00:00:00.000+01:00, prettyPrintStartDate=16 Feb, iso8601EndDate=2014-02-22T00:00:00.000+01:00, prettyPrintEndDate=22 Feb, offerType=WEEKLY] Offer [offerId=f5b8b110-9c77-11e3-b3db-3c970e02b4ec, offerImages=[], offerDescription=asas, header=asasa, startDate=Sun Feb 16 00:00:00 CET 2014, endDate=Sat Feb 22 00:00:00 CET 2014, city=, worldwide=false, iso8601StartDate=2014-02-16T00:00:00.000+01:00, prettyPrintStartDate=16 Feb, iso8601EndDate=2014-02-22T00:00:00.000+01:00, prettyPrintEndDate=22 Feb, offerType=WEEKLY]

我不知道问题是什么,因为值传递并且在那里。任何线索..?

This question already has an answer here:

Object passed via jsp:param throws javax.el.PropertyNotFoundException: Property 'foo' not found on type java.lang.String 1 answer

I have a jsp like following

<c:forEach items="${brand.weeklyOffers}" var="weeklyOffer"> <jsp:include page="offer.jsp"> <jsp:param name="offer" value="${weeklyOffer}" /> </jsp:include> </c:forEach>

My offer jsp looks like followig

<c:set var="offer" value="${param.offer}"/> <div class="accordion-group"> <div class="accordion-heading"> <a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion2" href="#collapse${param.offer.offerId}"><b>${offer.header}</b></a> </div>

throws the following exception

Caused by: javax.el.PropertyNotFoundException: Property 'offerId' not found on type java.lang.String

but when i do

<c:out value="${param.offer}"/>

in offer.jsp than i can see the follwoing result.

Offer [offerId=ec431f30-9c77-11e3-b3db-3c970e02b4ec, offerImages=[/offer-images/ec431f30-9c77-11e3-b3db-3c970e02b4ec/ec43e280-9c77-11e3-b3db-3c970e02b4ec.jpg], offerDescription=sasa, header=Buy 2 get 1 free, startDate=Sun Feb 16 00:00:00 CET 2014, endDate=Sat Feb 22 00:00:00 CET 2014, city=Munich, worldwide=false, iso8601StartDate=2014-02-16T00:00:00.000+01:00, prettyPrintStartDate=16 Feb, iso8601EndDate=2014-02-22T00:00:00.000+01:00, prettyPrintEndDate=22 Feb, offerType=WEEKLY] Offer [offerId=f5b8b110-9c77-11e3-b3db-3c970e02b4ec, offerImages=[], offerDescription=asas, header=asasa, startDate=Sun Feb 16 00:00:00 CET 2014, endDate=Sat Feb 22 00:00:00 CET 2014, city=, worldwide=false, iso8601StartDate=2014-02-16T00:00:00.000+01:00, prettyPrintStartDate=16 Feb, iso8601EndDate=2014-02-22T00:00:00.000+01:00, prettyPrintEndDate=22 Feb, offerType=WEEKLY]

I don't know what is the problem since the values are passed and are there.any clue..?

最满意答案

jsp:param将字符串参数传递给包含的JSP。 因此,您所看到的是在weeklyOffer bean上调用toString()的结果。 此String是作为参数传递给包含的JSP的内容。

如果要传递对象本身,则可以在include之前将其存储在请求属性中:

<c:set value="${weeklyOffer}" var="offer" scope="request"/>

或者将包含的JSP转换为接受商品作为参数的标签文件 。

jsp:param passes string parameters to the included JSP. What you're seeing is thus the result of calling toString() on your weeklyOffer bean. And this String is what is passed as parameter to the included JSP.

If you want to pass the object itself, then you can store it in a request attribute before the include:

<c:set value="${weeklyOffer}" var="offer" scope="request"/>

or transform your included JSP into a tag file accepting an offer as parameter.

更多推荐

jsp,offer,param,Feb,电脑培训,计算机培训,IT培训"/> <meta name="descripti

本文发布于:2023-08-07 18:14:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465118.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:jsp   param   error   duplicate   passing

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!