WordCount.jsp<%@ taglib uri = "http://localhost:8080/WordCountTag/taglib" prefix = "ics" %>
<html>
<head>
<title>
WordCountJSP
</title>
</head>
<body bgcolor = white>
<center>
<font color = '#009999' size = '4' face = 'Arial'>
<STRONG>Using Custom JSP Tag to Count Words</STRONG>
</font>
</center>
<hr/>
<center>
<form action = "WordCount.jsp" method = "post">
<TEXTAREA rows = "10" cols = "58" name = "input">Enter A Brief Description Here</TEXTAREA>
<BR></BR>
You have entered<ics:wordcount inputName = "input" warnEmpty = "true"/>
words in the above text area.
<br></br>
<input type = "submit" name = "Submit" value = "Count Words">
</form>
</center>
</html>
--------------------------------------------------------------------------------------
sampleTag.tld<taglib xmlns = "http://java.sun.com/xml/ns/j2ee"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://java.sun.com/xml/ns/j2ee/webjsptaglibrary_2_0.xsd"
version = "2.0">
  <display-name>JSP_Tag</display-name>
  <tlib-version>1.0</tlib-version>
  <jsp-version>2.0</jsp-version>
  <short-name>ics</short-name>
  <uri>http://localhost:8080/WordCountTag/taglib</uri><tag>
  <name>wordcount</name>
  <tag-class>WordCount</tag-class>
  <body-content>empty</body-content>
  <attribute>
    <name>inputName</name>
    <required>true</required>
    <rtexprvalue>false</rtexprvalue>
  </attribute>
  <attribute>
    <name>warnEmpty</name>
    <required>true</required>
    <rtexprvalue>true</rtexprvalue>
    <type>boolean</type>
  </attribute>
</tag></taglib>
-------------------------------------------------------------------------------------
WordCount.javaimport java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;public class WordCount extends TagSupport
{
    String inputName;
    boolean warnEmpty;
    String inputWord;    public void setInputName(String _inputName)
    {
        inputName = _inputName;
    }    public void setWarnEmpty(boolean _warnEmpty)
    {
        warnEmpty = _warnEmpty;
    }
  
    public int doEndTag() throws JspException
    {
        JspWriter out = pageContext.getOut();
        inputWord = pageContext.getRequest().getParameter(inputName);
        try
        {
             if((inputWord == null) && (warnEmpty == true))
             {
                 out.println("<font color = 'red'> None Input Found! Input Again </font>");
             }
             else 
                 if(inputWord == null)
                 {
                     out.println("0");
                 }
                 else
                 {
                     StringTokenizer st = new StringTokenizer(inputWord);
                     int wordNumber = st.countTokens();
                     out.println(wordNumber);
                 }
        } 
        catch(IOException ioe)
        {
             System.out.println("Error:" + ioe.getMessage());
        }
        return EVAL_PAGE;
    }
}其中sampleTag.tld 放在         /WordCountTag/WEB-INF 下
编译后的WordCount.class放在    /WordCountTag/WEB-INF/classes 下
WordCount.jsp放在              /WordCountTag下提出请求http://localhost:8080/WordCountTag/WordCount.jsp就出错了
HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: 19 in the jsp file: /WordCount.jsp
Generated servlet error:
WordCount cannot be resolved to a typeAn error occurred at line: 19 in the jsp file: /WordCount.jsp
Generated servlet error:
WordCount cannot be resolved to a typeAn error occurred at line: 19 in the jsp file: /WordCount.jsp
Generated servlet error:
WordCount cannot be resolved to a type