javax.el.ELException: 无法将 class java.lang.String 类型的 2015-12-03 18:50 转换为 class java.util.Date?
javax.el.ELException: Cannot convert 2015-12-03 18:50 of type class java.lang.String to class java.util.Date?
当我用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)
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"/>
当我用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)
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"/>