1

我正在创建一个.tagx文件,以便在不传递java.util.Date.

到目前为止,这就是我所做的。我无法让date变量的值增加day一。我试图用公式重新设置date使用<c:set>标签的值,index * (24 * 24 * 60 * 1000)它会javax.el.ELException在该行返回。

这是我到目前为止所做的代码。

<code>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jsp/jstl/core" 
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:fmt="http://java.sun.com/jstl/fmt_rt" 
xmlns:spring="http://www.springframework.org/tags" 
xmlns:form="http://www.springframework.org/tags/form" 
version="2.0">
<jsp:output omit-xml-declaration="yes" />
<jsp:useBean id="date" class="java.util.Date" />

<jsp:directive.attribute name="path" type="String" required="true" rtexprvalue="true" description="The name and id of select tag" />
<jsp:directive.attribute name="classVal" type="String" required="true" rtexprvalue="true" description="The class style to be used by this select" />
<jsp:directive.attribute name="noOfDays" type="Integer" required="true" rtexprvalue="true" description="Number of days to be printed on the selection" />

<select id="${path }" name="${path }" class="${classVal }">
    <option value=""></option>
    <c:forEach var="index" begin="1" end="${noOfDays }">
        <fmt:formatDate value="${date }" pattern="yyyy/MM/dd" var="dateKey" />
        <fmt:formatDate value="${date }" pattern="MM/dd (EEE)" var="dateValue" />
        <option value="${dateKey }">${dateValue }</option>
    </c:forEach>
</select>

</jsp:root>
</code>
4

2 回答 2

0

I've figured out a way that can solve this by inserting this code at the end of the loop

<jsp:setProperty property="time" name="date" value="${date.getTime() + (24*60*60*1000)}" />
于 2013-10-29T08:01:51.170 回答
0

当我像这样将 fmt:formatDate 与 Expression Language (EL) 一起使用时遇到了同样的问题

<fmt:formatDate pattern="yyyy" value="${coverDate}" var="year" />

错误是这样的

 EL expression '${coverDate}' is only allowed for attributes with rtexprvalue='true'.

整个问题只是因为wrong import

<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>

正确的导入应该是

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

希望这可以节省您的时间

于 2017-06-06T13:20:12.620 回答