自學(xué)JSP自定義標(biāo)簽的時(shí)候遇到的問(wèn)題控制臺(tái)提示數(shù)字格式化錯(cuò)誤,不知道是那里有格式化了,我的代碼只格式化了時(shí)間,而且我檢查了覺(jué)得沒(méi)問(wèn)題。刷新頁(yè)面變換的提示下面兩個(gè)錯(cuò)誤,這個(gè)提示一般來(lái)說(shuō)是jar包的問(wèn)題,可我沒(méi)有引用jar包以下是代碼:DateTage.java代碼:package?org.ydyy.zjj;
import?java.io.IOException;
import?java.text.SimpleDateFormat;
import?java.util.Date;
import?javax.servlet.jsp.JspException;
import?javax.servlet.jsp.JspWriter;
import?javax.servlet.jsp.tagext.TagSupport;
public?class?DateTag?extends?TagSupport?{
????private?String?format;
????@Override
????public?int?doStartTag()?throws?JspException?{
????????SimpleDateFormat?sdf?=?new?SimpleDateFormat(this.format);
????????try?{
????????????super.pageContext.getOut().write(sdf.format(new?Date()));
????????}?catch?(IOException?e)?{
????????????e.printStackTrace();
????????}
????????return?TagSupport.SKIP_BODY;
????}
????public?String?getFormat()?{
????????return?format;
????}
????public?void?setFormat(String?format)?{
????????this.format?=?format;
????}
}datetag.tld文件代碼:<?xml?version="1.0"?encoding="UTF-8"?>
<!DOCTYPE?taglib?PUBLIC?"-//Sun?Microsystems,?Inc.//DTD?JSP?Tag?Library?1.2//EN"?"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd"?>
<taglib>
????<tlib-version>tlib-version</tlib-version>
????<jsp-version>jsp-version</jsp-version>
????<short-name>short-name</short-name>
????<tag>
????????<name>date</name>
????????<tag-class>org.ydyy.zjj.DateTag</tag-class>
????????<body-content>empty</body-content>
????????<attribute>
????????????<name>format</name>
????????????<required>true</required>
????????????<rtexprvalue>true</rtexprvalue>
????????</attribute>
????</tag>
</taglib>web.xml文件中的聲明(對(duì)tld文件進(jìn)行名稱(chēng)映射,便于在jsp中使用映射名稱(chēng)):<taglib>
??<taglib-uri>mldn_date</taglib-uri>
??<taglib-location>/WEB-INF/datetag.tld</taglib-location>
</taglib>Date.jsp文件代碼<%@?page?language="java"?contentType="text/html;?charset=ISO-8859-1"
????pageEncoding="ISO-8859-1"%>
????<%@?taglib?prefix="mytag"?uri="mldn_date"?%>
<!DOCTYPE?html?PUBLIC?"-//W3C//DTD?HTML?4.01?Transitional//EN"?"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta?http-equiv="Content-Type"?content="text/html;?charset=ISO-8859-1">
<title>Insert?title?here</title>
</head>
<body>
????<h1>
????????定義有屬性的標(biāo)簽
????????<mytag:date?format="yyyy-MM-dd?HH:mm:ss:SSS"/>
????</h1>
</body>
</html>寫(xiě)了這么多勞煩各位看看了,解救我這個(gè)小白。
1 回答

zeng_建軍
TA貢獻(xiàn)25條經(jīng)驗(yàn) 獲得超16個(gè)贊
那么久了竟然也沒(méi)人回答,雖然問(wèn)題早就解決了,連想要采納個(gè)回答都沒(méi)有?
添加回答
舉報(bào)
0/150
提交
取消