解决:According to TLD or attribute directive in tag file, attribute value does not accept any express。

来源:互联网 发布:快压软件官方下载 编辑:程序博客网 时间:2024/06/05 09:41

背景:在mysql中有一个字段声明为datetime类型,在用hibernate映射时对应的类型为java.util.Date。因此从数据库中读出来,在前台jsp页面显示时,日期格式为年月日,时分秒,毫秒,例1986:07:26 09:07:21 0。日期在实体类和映射文件中已经声明为java.util.Date类型。

实体类代码:

[java] view plain copy
  1. public Date startTime;  
  2. public Date closeTime;  
hibernate关于这两个字段的映射代码:

[java] view plain copy
  1. <property name="costTime" type="integer">  
  2.     <column name="CostTime" length="50" not-null="true" />  
  3. </property>  
  4. <property name="startTime" type="java.util.Date">  
  5.     <column name="StartTime" length="50" not-null="true" />  
  6. </property>  

最开始用<s:property value="startTime"></s:property>得出的时间比较怪,是:99-2-26 4:22:50.000 

而用el表达式${startTime}得出的时间是1999-02-26 04:22:50.0。

而我想要的时间格式是1999-02-26 04:22:50。

因此用到了jstl标签里的<fmt:formatDate>格式如下:<fmt:formatDate pattern="yyyy:mm:dd HH:mm:ss" value="${startTime}"></fmt:formatDate>

然而报了异常:According to TLD or attribute directive in tag file, attribute value does not accept any expressions

查询之后得到的解决办法有两种:

 一、在page指令里,加入isELIgnored="true"属性,即
<%@ page language="java" contentType="text/html;charset=gbk"  isELIgnored="true" %>这个是忽略EL表达式,虽然可以解决问题,但其他处的EL表达式会被当做字符串输出,不建议使用。

二、把<%@ taglib prefix="c" uri="http://java.sun.com/jstl/fmt" %>变为:

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

原理(摘抄):应用部署运行的时候出现JSP异常发生在使用JSTL库的时候: According to TLD or attribute directive in tag file, attribute value does not accept any expressions,可能是因为使用了JSP2.0版本同时又没有使用JSTL core库的备用版本(RT)。

最终页面首部:

[java] view plain copy
  1. <%@ page language="java" contentType="text/html; charset=UTF-8"  
  2.     pageEncoding="UTF-8" %>  
  3. <%@ taglib prefix="s" uri="/struts-tags"%>      
  4. <%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt"%>   
  5. <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>   
输出时使用:
[java] view plain copy
  1. <fmt:formatDate pattern="yyyy:mm:dd HH:mm:ss" value="${startTime}"></fmt:formatDate>  

注:startTime代表本案例中使用的字段名。

用到的JSTL的jar包:jstl.jar和jstl-standard.jar。下载地址:http://jarfiles.pandaidea.com/。


阅读全文
0 0