自定义标签怎么老是出错

yuhh666 2006-12-22 02:04:18
哪位大哥帮帮我?
出错信息为
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: /MyJsp.jsp(9,0) Unable to load tag handler class "edu.j2ee.shop.infoTagExample" for tag "mytag:info"
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:200)
org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1318)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1560)
org.apache.jasper.compiler.Parser.parse(Parser.java:126)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:220)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:101)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:203)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:470)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.

我写的标签处理类是infoTagExample
package edu.j2ee.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)
{
username = user;
}

public int doStartTag() throws JspTagException
{
System.out.println("doStartTag");
try
{
pageContext.getOut().write("welcome " + username);

}
catch(Exception e)
{
e.printStackTrace();
}
return SKIP_BODY;

}

}
定义的TLD文件为mytld.tld

<taglib version="2.4"
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
http://java.sun.com/xml/ns/j2ee/web-app_2_0.xsd">

<description>this taglib provides tag example.</description>
<display-name>JSTL XML</display-name>
<tlib-version>1.2</tlib-version>
<short-name>mytag</short-name>
<uri>http://java.sun.com/jsp/jstl/xml</uri>
<tag>
<name>info</name>
<tag-class>edu.j2ee.shop.infoTagExample</tag-class>
<body-content>empty</body-content>
<attribute>
<name>userName</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>

</tag>
</taglib>
web.xml文件为
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
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
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Welcome to tomcat</display-name>
<description>JSP example</description>
<taglib>
<taglib-uri>/demotag</taglib-uri>
<taglib-location>/WEB-INF/mytag.tld</taglib-location>
</taglib>

</web-app>
jsp为
<%@ taglib uri="/demotag" 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>
</html>
出错信息为:
type Status report

message /tag/MyJsp.jsp

description The requested resource (/tag/MyJsp.jsp) is not available.

哪位大哥帮帮忙?
...全文
154 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
shine333 2006-12-22
  • 打赏
  • 举报
回复
tld里面定义edu.j2ee.shop.infoTagExample

java里面却是package edu.j2ee.tag;

81,087

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧