我正在尝试将一些时间戳值从集合转换为人类可读的日期格式。在一个 jsp 中,我编写了这个循环:
<c:forEach items="${tokenCollection}" var="tokenCollection" varStatus="status">
<jsp:setProperty name="dateValue" property="time" value="${tokenCollection.value.timestamp}" />
<fmt:formatDate value="${dateValue}" pattern="MM/dd/yyyy HH:mm" />
<!-- Correctly prints values as "40aa4ab4-f6c1-458a-9v3d-5d13b872d9c2" -->
<c:out value="${tokenCollection.value.value}"/>
<!-- Correctly prints values as "1378722681816" -->
<c:out value="${tokenCollection.value.timestamp}"/>
</c:forEach>
不幸的是,我通过运行它得到的只是:
org.apache.jasper.JasperException: An exception occurred processing JSP page /session_management.jsp at line 36
33: <p>Dati di sessione - utente "<c:out value="${username}" />"</p>
34:
35: <c:forEach items="${tokenCollection}" var="tokenCollection" varStatus="status">
36: <jsp:setProperty name="dateValue" property="time" value="${tokenCollection.value.timestamp}" />
37: <fmt:formatDate value="${dateValue}" pattern="MM/dd/yyyy HH:mm" />
38: <c:out value="${tokenCollection.value.value}"/>
39: <c:out value="${tokenCollection.value.timestamp}"/>
org.apache.jasper.JasperException: org.apache.jasper.JasperException: java.lang.NumberFormatException: For input string: "${tokenCollection.value.timestamp}"
如评论中所述,值被正确检索,因此 ${tokenCollection.value.timestamp} 绝对是一个时间戳(如 1378722681816)。尽管如此,我还是不知道如何解决这个问题,或者我到底错在哪里。有什么提示吗?