当我在我的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;
}
}
答案 0 :(得分:0)
<jsp-version>VERSION</jsp-version>
其中VERSION必须为浮点值,其中之一:1.1 / 1.2 / 2.0 / 2.1 / 2.2 / 2.3
这取决于您使用的Java Servlet容器和使用的版本。