jstl的fmt:formatDate标签和el表达式

jstl <fmt:formatDate> 类型转换问题和el表达式获取不了后端返回值

 

错误提示1:类型不能被转换

HTTP Status 500 - Unable to convert string "${item.items_creattime }" 
to class "java.util.Date" for attribute "value": 
Property Editor not registered with the PropertyEditorManager

错误提示2:值不能显示到页面

jstl的fmt:formatDate标签和el表达式

 

解决方法

jsp页面

jstl引入

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

forEach编写

<c:forEach items="${itemsList}" var="item">
    <tr>
        <td><input type="checkbox" name="items_ids" value="${item.id }"></td>
        <td>${item.items_name }</td>
        <td>${item.items_price }</td>
        <td><fmt:formatDate value="${item.items_creattime }" pattern="yyyy:MM:dd HH:mm:ss"/></td>
        <td>${item.items_detail }</td>
        <td><a href="${PageContext.request.ContextPath }/items/editItems.action?id=${item.id}">修改</a></td>
        <td><a href="${PageContext.request.ContextPath }/items/deleteItems.action?id=${item.id}">删除</a></td>
    </tr>
</c:forEach>

web.xml

修改前

jstl的fmt:formatDate标签和el表达式

修改后

<web-app 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID"
    version="2.5">

因为Tomcat的支持web.xml 的Servlet是 2.5版本

 

测试结果

jstl的fmt:formatDate标签和el表达式

注意:数据仅用于案例测试,不做其他性质考虑。