当我在Jsp程序中使用属性自定义标记时,出了点问题:
具有路径[/ Tag]的上下文中Servlet [jsp]的Servlet.service()引发了异常[无法为JSP编译类]java.lang.NumberFormatException:对于输入字符串:“ tag”
这里是详细信息:
tag.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="tag" uri="/WEB-INF/tag.tld"%>
<!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=UTF-8">
<title></title>
</head>
<body>
<tag:date format="yyyy-MM-dd HH:mm:ss" />
</body>
</html>
tag.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>1.0</tlib-version>
<jsp-version>tag</jsp-version>
<short-name>tag</short-name>
<tag>
<name>date</name>
<tag-class>com.cn.tag.DateTag</tag-class>
<body-content>empty</body-content>
<attribute>
<name>format</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
DateTag.java
package com.cn.tag;
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(format);
try {
pageContext.getOut().write(sdf.format(new Date()));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return TagSupport.SKIP_BODY;
}
public String getFormat() {
return format;
}
public void setFormat(String format) {
this.format = format;
}
}
<jsp-version>VERSION</jsp-version>