问:jsp自定义标签的问题Unable to load tag handler class
Tomcat下编译出现的问题:
org.apache.jasper.JasperException: /jsp/taginfo.jsp(10,1) Unable to load tag handler class "edu.jsp.tag.InfoTagExample" for tag "mytag:info"
自习检查程序,也没发现问题,help
4个文件分别如下:
/amytags/jsp/taginfo.jsp
---------------------------------------------
<%@ taglib uri="/WEB-INF/mytag.tld" prefix="mytag" %>
<html>
<head>
<title>custom tag</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<HR>
<mytag:info userName="John"/>
<HR>
</body>
/amytags/Web-inf/mytag.tld
-------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<!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.2</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>mytag</short-name>
<description>This taglib provides tag example</description>
<tag>
<name>info</name>
<tag-class>edu.jsp.tag.InfoTagExample</tag-class>
<body-content>empty</body-content>
<attribute>
<name>userName</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
/amytags/Web-inf/web.xml
-------------------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<!-- My own Tag Library Descriptors -->
<taglib>
<taglib-uri>/WEB-INF/mytag.tld</taglib-uri>
<taglib-location>/WEB-INF/mytag.tld</taglib-location>
</taglib>
</web-app>
/amytags/Web-inf/classes/edu/jsp/tag/InfoTagExample.java
----------------------------------------------------------
package edu.jsp.tag;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.Writer;
import java.io.IOException;
public class InfoTagExample extends TagSupport
{
String userName;
public InfoTagExample()
{
super();
}
public void setUserName(String user)
{
this.userName = user;
}
public int doStratTag() throws JspTagException
{
System.out.println("doStartTag");
try{
pageContext.getOut().write("welcome" + userName);
}
catch(Exception e){
e.printStackTrace();
}
return (SKIP_BODY);
}
}