【问题标题】:error in passing param from one jsp to another [duplicate]将参数从一个jsp传递到另一个时出错[重复]
【发布时间】:2014-03-25 00:38:09
【问题描述】:

我有一个类似下面的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]

我不知道问题出在哪里,因为值已通过并且存在。任何线索..?

【问题讨论】:

    标签: jsp jstl


    【解决方案1】:

    jsp:param 将字符串参数传递给包含的 JSP。因此,您看到的是在您的每周优惠 bean 上调用 toString() 的结果。而这个 String 就是作为参数传递给包含的 JSP 的。

    如果你想传递对象本身,那么你可以将它存储在包含之前的请求属性中:

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

    或将您包含的 JSP 转换为 a tag file 接受报价作为参数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-03
      • 2012-04-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多