关于开发jsp标签的环境配置问题

06-07-27 yeshenghai
有四个文件,一个jsp,一个xml,一个tld,一个java文,这几个文件搭建一个WEB应用(在tomcat下).

1,jsp:

<%@ taglib uri="date" prefix="MyDate"%>

<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head>

<title> New Document </title>

</head>

<body>

<MyDate:displayDate/>

</body>

</html>

2,java

package lesson.taglib;

import java.util.*;

import javax.servlet.jsp.*;

import javax.servlet.jsp.tagext.*;

public class DisplayDate extends TagSupport{

public int doStartTag() throws JspException{

JspWriter out = pageContext.getOut();

try{

out.println(new Date());

}catch(Exception e){

e.printStackTrace();

}

return SKIP_BODY;

}

}

3,xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

<taglib>

<taglib-uri>date</taglib-uri>

<taglib-location>/WEB-INF/date.tld</taglib-location>

</taglib>

</web-app>

4,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>date</short-name>

<description>

This is a show date taglib example.

</description>

<tag>

<name>displayDate</name>

<tag-class>lesson.taglib.DisplayDate</tag-class>

<body-content>empty</body-content>

</tag>

</taglib>

问题在于,在tomcat下运行会报错,而且全班几十个人,有的机子运行正常,有的机子运行不正常.重装tomcat无济于是.有的机子重装了操作系统,就正常了.

不正常的原因(tomcat显示的错误提示如下.):

HTTP Status 500 -

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

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.<init>(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:272)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

java.lang.NoSuchMethodError: javax.servlet.jsp.tagext.TagInfo.<init>(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:435)

org.apache.jasper.compiler.TagLibraryInfoImpl.parseTLD(TagLibraryInfoImpl.java:24

org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:162)

org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:423)

org.apache.jasper.compiler.Parser.parseDirective(Parser.java:492)

org.apache.jasper.compiler.Parser.parseElements(Parser.java:1552)

org.apache.jasper.compiler.Parser.parse(Parser.java:126)

org.apache.jasper.compiler.ParserController.doParse(ParserController.java:211)

org.apache.jasper.compiler.ParserController.parse(ParserController.java:100)

org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:146)

org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)

org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)

org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)

org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

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

猜你喜欢