【问题标题】:Jsp java.lang.NumberFormatException: For input string: "tag"Jsp java.lang.NumberFormatException:对于输入字符串:“tag”
【发布时间】:2017-08-29 20:33:55
【问题描述】:

当我在我的Jsp程序中自定义带有属性的标签时,出现了问题:

Servlet.service() for servlet [jsp] in context with path [/Tag] 引发异常 [Unable to compile class for 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;   
  } 
}

【问题讨论】:

标签: java jsp servlets


【解决方案1】:
<jsp-version>VERSION</jsp-version>

其中 VERSION 必须是浮点值,其中之一:1.1 / 1.2 / 2.0 / 2.1 / 2.2 / 2.3

这取决于你使用什么 Java Servlet Container 和版本。

对于tomcat:http://tomcat.apache.org/whichversion.html

对于 jboss:https://access.redhat.com/articles/113373

【讨论】:

    猜你喜欢
    • 2013-01-29
    • 2020-01-01
    • 2012-12-05
    • 2013-09-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多