学习tag标签时,遇到下列错误:(困扰俺很久)还请众高手看看是怎么回事!!!!谢谢!!
当提交表单时(没有密码)! tomcat5.0报以下错误:
----------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: javax.servlet.jsp.tagext.TagInfo.(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljavax/servlet/jsp/tagext/TagLibraryInfo;Ljavax/servlet/jsp/tagext/TagExtraInfo;[Ljavax/servlet/jsp/tagext/TagAttributeInfo;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljavax/servlet/jsp/tagext/TagVariableInfo;Z)V
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:256)
javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
mypack.DispatcherServlet.doPost(DispatcherServlet.java:38)
javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
root cause
java.lang.NoSuchMethodError: javax.servlet.jsp.tagext.TagInfo.(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljavax/servlet/jsp/tagext/TagLibraryInfo;Ljavax/servlet/jsp/tagext/TagExtraInfo;[Ljavax/servlet/jsp/tagext/TagAttributeInfo;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljavax/servlet/jsp/tagext/TagVariableInfo;Z)V
org.apache.jasper.compiler.TagLibraryInfoImpl.createTagInfo(TagLibraryInfoImpl.java:471)
org.apache.jasper.compiler.TagLibraryInfoImpl.parseTLD(TagLibraryInfoImpl.java:295)
org.apache.jasper.compiler.TagLibraryInfoImpl.(TagLibraryInfoImpl.java:204)
org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:460)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:525)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1625)
org.apache.jasper.compiler.Parser.parse(Parser.java:173)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:247)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:149)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:135)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:243)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:437)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:555)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:291)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
mypack.DispatcherServlet.doPost(DispatcherServlet.java:38)
javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
note The full stack trace of the root cause is available in the Tomcat logs.
----------------------------------------------------------------
以下是原代码!
---------------------------------------------------------------
login.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>helloapp------------login</title>
</head>
<body>
<br />
<form name="loginForm" action="dispatcher" method="post">
<table >
<tr>
<td><div align="right">User Name:</div></td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td><div align="right">Password:</div></td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="Submit" /></td>
</tr>
</table>
</form>
</body>
</html>
-------------------------------------------------------------
hello.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ taglib uri="/mytaglib" prefix="mm"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>helloapp</title>
</head>
<body>
<b><mm:hello/>:<%=request.getAttribute("USER")%></b>
</body>
</html>
--------------------------------------------------------------
web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC
'-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN'
'http://java.sun.com/j2ee/dtds/web-app_2_3.dtd'>
<web-app>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>mypack.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/dispatcher</url-pattern>
</servlet-mapping>
<taglib>
<taglib-uri>/mytaglib</taglib-uri>
<taglib-location>/WEB-INF/mytaglib.tld</taglib-location>
</taglib>
</web-app>
----------------------------------------------------------------
mytaglib.tld
<?xml version="1.0" encoding="gb2312" ?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<!-- a tag library descriptor -->
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>mytaglib</shortname>
<uri>/mytaglib</uri>
<tag>
<name>hello</name>
<tagclass>mypack.HelloTag</tagclass>
<bodycontent>empty</bodycontent>
<info>Just Say Hello</info>
</tag>
</taglib>
------------------------------------------------------------
DispatcherServlet.java
// Java Document
package mypack;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class DispatcherServlet extends HttpServlet{
private String target="/hello.jsp";
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
//If it is a get request forward to doPost()
doPost(request,response);
}
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException {
//Get the username from the request
String username=request.getParameter("username");
//Get the password from the request
String password=request.getParameter("password");
//Add the user to the request
request.setAttribute("USER",username);
request.setAttribute("PASSWORD",password);
//Forward the request to the target named
ServletContext context=getServletContext();
System.out.println("Redirect to "+ target);
RequestDispatcher dispatcher=context.getRequestDispatcher(target);
dispatcher.forward(request,response);
}
public void destroy(){
}
}
--------------------------------------------------------------
HelloTag.java
// Java Document
package mypack;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;
public class HelloTag extends TagSupport {
public void HelloTag(){}
//Method called when the closing hello tag is encountered
public int doEndTag() throws JspException{
try{
//We use the pageContext to get a Writer
//We then print the text string Hello
pageContext.getOut().print("Hello");
}
catch(Exception e){
throw new JspTagException(e.getMessage());
}
//We want to return SKIP_BODY because this Tag does not support a Tag Body
return SKIP_BODY;
}
public void release(){
//Call the parent's release to release any resource
//use by the parent tag.
//This is just good practice for when you start creating
//hierarchies of tags
super.release();
}
}
----------------------------------------------------------
谢谢各位啦:-)
[此贴子已经被作者于2006-7-25 20:18:30编辑过]