gpt4 book ai didi

jsp - 在 JSP 中使用 EL 时出错

转载 作者:行者123 更新时间:2023-12-04 05:34:29 26 4
gpt4 key购买 nike

我使用了 El ,但它无效。
我收到一个错误:javax.el.ELException: Cannot convert 1 of type class java.lang.String to class java.lang.Long . 1是计数。

     <h3>My Shopping</h3>
<c:set var="count" value=" ${sessionScope.cart.count}" />
${count}
<%--
<c:set var="cart" value="${sessionScope.cart}" />
<c:set var="count" value=" ${sessionScope.cart.count}" />
<br/>
<c:if test="${count < 1}" >
No Product in your cart
</c:if>
<c:if test="${count > 0}">
<c:set var="listCart" value="${sessionScope.cart.cart}" />

最佳答案

此异常表明 ${count}String ,不是 Long (或 Integer ,也可以)。

前提是count cart 的属性(property) session 范围中的 bean 已经是正确的类型,那么我在到目前为止发布的代码中可以看到的唯一原因是值之前有一个悬空的前导空格。

<c:set var="count" value=" ${sessionScope.cart.count}" />
<!-- ---------------------^ -->

这有效地使它成为 String " 1" 的值这显然不是一个有效的数字。删除那个有问题的空间应该可以解决问题。

关于jsp - 在 JSP 中使用 EL 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12145978/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com