您的位置:首页 > 产品设计 > UI/UE

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

2016-08-09 23:04 726 查看
http://blog.csdn.net/lzblog/article/details/22076893

——————————————————————————————————————————————————————————

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

实体类代码:

[java] view plain copy





public Date startTime;

public Date closeTime;

hibernate关于这两个字段的映射代码:

[java] view plain copy





<property name="costTime" type="integer">

<column name="CostTime" length="50" not-null="true" />

</property>

<property name="startTime" type="java.util.Date">

<column name="StartTime" length="50" not-null="true" />

</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="fmt" uri="http://java.sun.com/jstl/fmt_rt"%>

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

原理(摘抄):应用部署运行的时候出现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





<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8" %>

<%@ taglib prefix="s" uri="/struts-tags"%>

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

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

输出时使用:

[java] view plain copy





<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/。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: