Women in Technology

Hear us Roar



Article:
  Designing JSP Custom Tag Libraries
Subject:   ERROR WHILE DISPLAYING JSP
Date:   2005-09-10 10:02:58
From:   kingviju
ERROR WHILE DISPLAYING JSP :
HTTP Status 500 -


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


type Exception report


message


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


exception


org.apache.jasper.JasperException: /Hello.jsp(9,4) No such tag hello in the tag library imported with prefix sample
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:49)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:383)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:174)
at org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:660)
at org.apache.jasper.compiler.Parser.parseElements(Parser.java:759)
at org.apache.jasper.compiler.Parser.parse(Parser.java:77)
at org.apache.jasper.compiler.ParserController.parse(ParserController.java:157)
at org.apache.jasper.compiler.ParserController.parse(ParserController.java:111)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:183)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)



I am using Tomcat4.1. And IntelliJ IDEA.
This IDE shows that my JSP which is having following statement :
<%@ taglib uri="oreillySample" prefix="sample"%>


Cannot Resolve tag library.


CAN SOMEBODY HELP ME IDENTIFY..WHERE AM I GOING WRONG ????


Here is my source code you can refer !!!!




---- JSP
<%@ page session="false" %>
<%@ taglib uri="oreillySample" prefix="sample"%>


<html>
<head>
<title>Your Standard Hello World Demo</title>
</head>
<body bgcolor="#ffffff">
<hr />
<sample:hello name="Sue"/>
<hr />
</body>
</html>


--- TLD
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">


<taglib>


<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>oreillySample</shortname>
<info>OReilly Sample Tag library</info>


<tag>
<name>Hello</name>
<tagclass>oreilly.examples.HelloTag</tagclass>
<bodycontent>empty</bodycontent>
<attribute>
<name>name</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
</tag>


</taglib>


--- WEB.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>


<display-name>
Tag Lib
</display-name>


<welcome-file-list>
<welcome-file>Hello.jsp</welcome-file>
</welcome-file-list>


<taglib>
<taglib-uri>oreillySample</taglib-uri>
<taglib-location>/WEB-INF/tlds/oreillySample.tld</taglib-location>
</taglib>


</web-app>


--- HelloTag.java


package oreilly.examples;


import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
/**
* This is a simple tag example to show how content is added to the
* output stream when a tag is encountered in a JSP page.
*/
public class HelloTag extends TagSupport {
private String name=null;
/**
* Getter/Setter for the attribute name as defined in the tld file
* for this tag
*/
public void setName(String value){
name = value;
}


public String getName(){
return(name);
}


/**
* doStartTag is called by the JSP container when the tag is encountered
*/
public int doStartTag() {
try {
JspWriter out = pageContext.getOut();
out.println("<table border=1>");
if (name != null)
out.println("<tr><td> HelloTag " + name + " </td></tr>");
else
out.println("<tr><td> HelloTag World </td></tr>");
} catch (Exception ex) {
throw new Error("All is not well in the world.");
}
// Must return SKIP_BODY because we are not supporting a body for this
// tag.
return SKIP_BODY;
}
/**
* doEndTag is called by the JSP container when the tag is closed
*/
public int doEndTag(){
try {
JspWriter out = pageContext.getOut();
out.println("</table>");
} catch (Exception ex){
throw new Error("All is not well in the world.");
}
return EVAL_PAGE;
}
}



The file structure is as follows :


Ch04
Hello.jsp
-> WEB-INF
web.xml
-->src\oreilly.examples.HelloTag.java
-->classes\oreilly.examples.HelloTag.class
-->tlds\oreillySample.tld


Full Threads Newest First

Showing messages 1 through 2 of 2.

  • ERROR WHILE DISPLAYING JSP
    2005-09-10 10:07:47  kingviju [View]

    I GOT THE PROBLEM RESOLVED. Simple mistake in jsp....

    Error :
    <sample:hello name="Sue"/>

    Resolved :
    <sample:Hello name="Sue"/>

    Now everthing is working fine !!


  • ERROR WHILE DISPLAYING JSP
    2006-11-09 21:20:32  indu_y [View]

    xml parsing error in file.document root element taglib must match document type element "null"