自學JSP自定義標簽的時候遇到的問題控制臺提示數字格式化錯誤,不知道是那里有格式化了,我的代碼只格式化了時間,而且我檢查了覺得沒問題。刷新頁面變換的提示下面兩個錯誤,這個提示一般來說是jar包的問題,可我沒有引用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文件中的聲明(對tld文件進行名稱映射,便于在jsp中使用映射名稱):<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>
????????定義有屬性的標簽
????????<mytag:date?format="yyyy-MM-dd?HH:mm:ss:SSS"/>
????</h1>
</body>
</html>寫了這么多勞煩各位看看了,解救我這個小白。
添加回答
舉報
0/150
提交
取消
