在JSTL< fmt:formatDate>中使用java.time.LocalDate行动 [英] Using java.time.LocalDate with JSTL <fmt:formatDate> action
问题描述
我一直无法弄清楚如何在JSP中显示java.time.LocalDate
值.
I haven't been able to figure out how to display a java.time.LocalDate
value in a JSP.
在我的JSP中,我有这个:
In my JSP, I have this:
<fmt:formatDate value="${std.datum}" type="date" pattern="dd.MM.yyyy" var="stdDatum" />
std.datum
的类型为 java.time.LocalDate .呈现JSP时,出现以下异常:
The std.datum
is of type java.time.LocalDate. When rendering the JSP I get this exception:
javax.el.ELException:
无法转换类型类别的2015-02-14 java.time.LocalDate到类java.util.Date
javax.el.ELException:
Cannot convert 2015-02-14 of type class java.time.LocalDate to class java.util.Date
我假设是转换?
那么可以通过<fmr:formatDate>
动作格式化 LocalDate 类的实例吗?
So is it possible to format an instance of LocalDate class with <fmr:formatDate>
action?
推荐答案
我假设是转换?
I'm assuming it's the conversion?
是的,这是与转换有关的异常.
Yes, it's a conversion related exception.
您可以首先使用 <fmt:parseDate>
action 来进行转换和然后使用
You could first use the <fmt:parseDate>
action from the JSTL's "I18n capable formatting tag library" to do the conversion and then do the formatting with the <fmt:formatDate>
action.
这里是一个例子:
<fmt:parseDate value="${std.datum}" type="date" pattern="yyyy-MM-dd" var="parsedDate" />
<fmt:formatDate value="${parsedDate}" type="date" pattern="dd.MM.yyyy" var="stdDatum" />
"JavaServer Pages™标准标记库(JSTL)" 规范 1.2版(请参见第109页).
This solution is also presented right in the "JavaServer Pages™ Standard Tag Library (JSTL)" specification version 1.2 (see page 109).
这篇关于在JSTL< fmt:formatDate>中使用java.time.LocalDate行动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!