标题:问一个关于tag标签的问题!(困扰)
只看楼主
ziyehanbin
Rank: 1
等 级:新手上路
帖 子:59
专家分:0
注 册:2005-10-16
 问题点数:0 回复次数:10 
问一个关于tag标签的问题!(困扰)

学习tag标签时,遇到下列错误:(困扰俺很久)还请众高手看看是怎么回事!!!!谢谢!!

当提交表单时(没有密码)! tomcat5.0报以下错误:

W3qQtmWn.rar (5.31 KB) 问一个关于tag标签的问题!(困扰)



----------------------------------------------------------------

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编辑过]

搜索更多相关主题的帖子: tag 困扰 
2006-07-25 20:17
神vLinux飘飘
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:浙江杭州
等 级:贵宾
威 望:91
帖 子:6140
专家分:217
注 册:2004-7-17
得分:0 
我好像没有看见你重写doStartTag()方法

淘宝杜琨
2006-07-25 20:43
ziyehanbin
Rank: 1
等 级:新手上路
帖 子:59
专家分:0
注 册:2005-10-16
得分:0 

不行呀!版主!我覆盖了doStartTag(),错误依旧!!请帮忙调试一下!谢谢!

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(){}

public int doStartTag() 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 int doEndTag() throws JspException{

return EVAL_PAGE;

}

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();
}

}


------------------------------------------------------------------------

Thanks!!!!!!!!!!!



2006-07-26 19:15
神vLinux飘飘
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:浙江杭州
等 级:贵宾
威 望:91
帖 子:6140
专家分:217
注 册:2004-7-17
得分:0 
SORRY,我忘记说了,还有doTag()方法也要重写

淘宝杜琨
2006-07-26 19:41
ziyehanbin
Rank: 1
等 级:新手上路
帖 子:59
专家分:0
注 册:2005-10-16
得分:0 

谢谢您的帮助!

刚才我用个空语句覆盖了doTag()方法,

public void doTag() throws JspException
{
//getJspContext().getOut().write("hello");
}

可问题没有解决!
我查了一些资料,doStartTag() doEndTag() 和 doTag() 方法并不需要同时覆盖呀!

您能帮我改一下程序吗! 不胜感谢!!


2006-07-26 20:38
神vLinux飘飘
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:浙江杭州
等 级:贵宾
威 望:91
帖 子:6140
专家分:217
注 册:2004-7-17
得分:0 
&lt;%@ taglib uri="/mytaglib" prefix="mm"%&gt;
这句,更改为
&lt;%@ taglib uri="/WEB-INF/mytaglib.tld" prefix="mm"%&gt;

淘宝杜琨
2006-07-26 21:03
ziyehanbin
Rank: 1
等 级:新手上路
帖 子:59
专家分:0
注 册:2005-10-16
得分:0 

您上面说的方法我早就试过了!!不行!呵呵!!

J道:http://www.jdon.com 彭晨阳(banq )老师说:

有两个重复的标签库包或类

我到现在也没弄懂他的话!汗!真笨!

-----------------------------------------------------------

今天在搭建struts的环境时,我把struts-blank.war安装后,其余均未动,
当我访问index.jsp时,tomcat抛出了与以上问题差不多的tag异常,是不是我的
tomcat5.0有问题呀!可我什么都未动,是从sun公司下载的呀!
两个问题差不多!真不知是哪出问题啦!!!!!

----------------------------------------------------------


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.TagAttributeInfo.(Ljava/lang/String;ZLjava/lang/String;ZZ)V
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:256)
javax.servlet.http.HttpServlet.service(HttpServlet.java:853)


root cause

java.lang.NoSuchMethodError: javax.servlet.jsp.tagext.TagAttributeInfo.(Ljava/lang/String;ZLjava/lang/String;ZZ)V
org.apache.jasper.compiler.TagLibraryInfoImpl.createAttribute(TagLibraryInfoImpl.java:577)
org.apache.jasper.compiler.TagLibraryInfoImpl.createTagInfo(TagLibraryInfoImpl.java:437)
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)


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

--------------------------------------------------------------------------



2006-07-26 21:56
神vLinux飘飘
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:浙江杭州
等 级:贵宾
威 望:91
帖 子:6140
专家分:217
注 册:2004-7-17
得分:0 
我不知道你的问题是怎么来的,干脆我写一个让你去参考得了。
因为我自己也很少些TAG,有了JSTL后我就一直很懒了。

淘宝杜琨
2006-07-26 22:01
神vLinux飘飘
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:浙江杭州
等 级:贵宾
威 望:91
帖 子:6140
专家分:217
注 册:2004-7-17
得分:0 
http://www.

淘宝杜琨
2006-07-26 22:03
ziyehanbin
Rank: 1
等 级:新手上路
帖 子:59
专家分:0
注 册:2005-10-16
得分:0 


ok,可以工作了!!

非常感谢您!!

把错误与大家分享:
---------------------------------------------------------------------------
我的TOMCAT加载了错误的 jsp-api.jar,或者有其他 JAR 与jsp-api.jar冲突。
我的 jsp-api 类是 JSP Spec 1.0/1.1的,应当是2.0

--------------------------------------------------------------------------
共同学习!多多指教!!!!!


2006-07-27 09:27



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-80228-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.145779 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved