File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes A strange problem with jsp custom tag. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "A strange problem with jsp custom tag." Watch "A strange problem with jsp custom tag." New topic
Author

A strange problem with jsp custom tag.

Bibhudutta Pradhan
Ranch Hand

Joined: Jun 24, 2011
Posts: 31

I create my project in eclipse, copy it and paste it in the C:\Tomcat 6.0\webapps .

I am trying to develop a simple jsp custom tag. The files i have used are as follows.


index.jsp
----------------------------------------------------
<%@ taglib
uri="WEB-INF/simpletags.tld"
prefix="jspx" %>

<html>
<title><jspx:hello/></title>
<body>
Executing your first custom tag... <b><jspx:hello/></b>
</body>
</html>
----------------------------------------------------



web.xml
--------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2.2.dtd">
<web-app>
<taglib>
<taglib-uri>
/WEB-INF/simpletags.tld
</taglib-uri>
<taglib-location>
/WEB-INF/simpletags.tld
</taglib-location>
</taglib>
</web-app>
-------------------------------------------------------------------------





simpletags.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>simp</shortname>
<uri> /WEB-INF/simpletags.tld </uri>
<info>
A simple sample tag library
</info>

<tag>
<name>hello</name>
<tagclass>book.simpletasks.HelloWorldTag</tagclass>
<bodycontent>empty</bodycontent>
<info>
Say hello.
</info>
</tag>
</taglib>
-----------------------------------------------------------------------






HelloWorldTag.java
-----------------------------------------------------
package com;

import java.io.IOException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;

public class HelloWorldTag extends TagSupport {

public int doStartTag()throws JspException
{
try
{
pageContext.getOut().print("Hello JSP tag World");
}
catch(IOException ioe)
{
throw new JspTagException("Error:IOException while writing to the user");
}
return SKIP_BODY;
}
}
-------------------------------------------------


I have been trying it since a week.
The problem is that as long as jsp-api.jar is under C:\Tomcat 6.0\webapps\myFirstCustomTag\WEB-INF\lib,
running index.jsp gives me following exception.
-----------------------------------------------------------------------------------------------------------------
exception

org.apache.jasper.JasperException: java.lang.NullPointerException
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:356)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause

java.lang.NullPointerException
org.apache.jsp.index_jsp._jspInit(index_jsp.java:30)
org.apache.jasper.runtime.HttpJspBase.init(HttpJspBase.java:52)
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:159)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

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


But when i remove the jsp-api.jar from C:\Tomcat 6.0\webapps\myFirstCustomTag\WEB-INF\lib,
the problem evaporates and the project runs normally. But WHY ? I cant understand .

Please help. Thanks in advance.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60056
    
  65

You should never put jsp-api.jar or servlet-api.jar in WEB-INF/lib. It just fouls things up with hard-to-diagnose errors. These jar files are provided by the container and should never be put into your web apps.

And I'd also advice to use proper URIs for your taglibs. You can use anything you want, but not following conventions just makes things harder than they need to be.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Pete Nelson
Ranch Hand

Joined: Aug 30, 2010
Posts: 147

Both web.xml and simpletags.tld use the URI '/WEB-INF/simpletags.tld', but your JSP references 'WEB-INF/simpletags.tld'. Are you sure your JSP container sees those as equivalent?


OCPJP
In preparing for battle I have always found that plans are useless, but planning is indispensable. -- Dwight D. Eisenhower
 
wood burning stoves
 
subject: A strange problem with jsp custom tag.
 
Similar Threads
Error using custom tag
Custom Tag NOT Compiling
Problem while running JSP Custom Tag
problem in Taglib in jsp
jsp custom tag issues