您的位置:首页 > Web前端 > JavaScript

解决jsp中input标签读取时间格式实例显示到页面

2016-09-22 15:56 721 查看
java中的代码:


private Date buildTime;
jsp中的代码:

<span style="font-family:KaiTi_GB2312;font-size:12px;"><input type="text" name="buildTime"  value="<fmt:formatDate  value="${currentAccount.buildTime}" type="both"/>"/></span>


这里我用到了jstl标签里的<fmt:formatDate>格式如下:<fmt:formatDate pattern="yyyy:mm:dd HH:mm:ss" value="${buildTime}"></fmt:formatDate>或是以下这样的写法<fmt:formatDate  value="${currentAccount.buildTime}"
type="both"/>
添加之后出现一个异常:
异常: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库)。
最后的jsp头部页面如下:

<span style="font-family:KaiTi_GB2312;font-size:12px;"><%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"  %>
<%@taglib  prefix="c"  uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %></span>


注:buildTime代表本例中的实例字段,currentAccount代表定义的实例常量
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  spring 标签 jsp jstl