javax.el.E​​LException:无法将类型为java.lang.String的2015-12-03 18:50转换为类java.util.Date?

时间:2015-12-03 10:48:30

标签: java jsp date format el

当我使用El表达式的时间值可以正常时,但格式化的时间一直存在问题,

这是我的代码和错误异常

<fmt:formatDate value="${active.expire_time}" pattern="yyyy-MM-dd HH:mm"/>

   javax.el.ELException: Cannot convert 2015-12-03 18:50 of type class java.lang.String to class java.util.Date
    org.apache.el.lang.ELSupport.coerceToType(ELSupport.java:419)
    org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
    org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:944)
    org.apache.jsp.pages.activityList_jsp._jspx_meth_fmt_005fformatDate_005f0(activityList_jsp.java:385)
    org.apache.jsp.pages.activityList_jsp._jspx_meth_c_005fforEach_005f0(activityList_jsp.java:348)
    org.apache.jsp.pages.activityList_jsp._jspx_meth_c_005fif_005f0(activityList_jsp.java:291)
    org.apache.jsp.pages.activityList_jsp._jspService(activityList_jsp.java:181)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1228)
    org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1011)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:955)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:150)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

1 个答案:

答案 0 :(得分:6)

active.expire_time变量是String,已经格式化了。

但是fmt:formatDate需要Date类型的变量。

或者您可以将active.expire_time转换为日期并显示:

<fmt:parseDate value="${active.expire_time}" pattern="yyyy-MM-dd HH:mm" var="myDate"/>
<fmt:formatDate value="${myDate}" pattern="yyyy-MM-dd HH:mm"/>