Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A strange problem with jsp custom tag.

 
Bibhudutta Pradhan
Ranch Hand
Posts: 31
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64708
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pete Nelson
Ranch Hand
Posts: 147
Debian Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic