Results 1 to 8 of 8
Thread: JSTL && NullPointerException
- 01-12-2010, 02:04 PM #1
Member
- Join Date
- Aug 2009
- Posts
- 25
- Rep Power
- 0
JSTL && NullPointerException
Hi All,Help needed to run JSTL 1.1 in Tomcat 6.0.20
I have placed the jstl.jar and standard.jar of the jakarta-taglibs-standard-1.1.2.zip in my project in WEB-INF/lib and i also placed there the jsp-api.jar;
My tag handler class named DateTag.java looks like this:
Code:
package tags;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
import java.util.*;
import java.io.*;
public class DateTag extends TagSupport{
private static final long serialVersionUID = 1L;
public int doStartTag()throws JspException,java.lang.NullPointerException
{
try
{
JspWriter out=pageContext.getOut();
out.println(new Date());
}
catch(java.lang.NullPointerException e)
{
System.out.println("Eroare "+e.getMessage());
}
catch(IOException e)
{
System.out.println("Eroare "+e.getMessage());
}
return SKIP_BODY;
}
}
END CODE
wow.tld for this tag handler looks like this:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<taglib xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd" version="2.1">
<description>Example of a simple tag library</description>
<tlib-version>1.1</tlib-version>
<short-name>wow</short-name>
<tag>
<name>dateTag</name>
<tag-class>tags.DateTag</tag-class>
<body-content>EMPTY</body-content>
<description>furnizeaza data curenta</description>
</tag>
</taglib>
End Code
web.xml looks in this way:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>JSP_Tag_Extension</display-name>
<jsp-config>
<taglib>
<taglib-uri>/WEB-INF/tlds/wow.tld</taglib-uri>
<taglib-location>/WEB-INF/tlds/wow.tld</taglib-location>
</taglib>
</jsp-config>
</web-app>
End Code
and finally dateTag.jsp (a jsp to test the dateTag custom action)
Code:
<%@ taglib uri="/WEB-INF/tlds/wow.tld" prefix="mk" %>
<p>Data curenta este:<mk:dateTag/></p>
When i compile my program, the program compiles successfully, but when i try to run it i get this error:
java.lang.NullPointerException.
I am really confused why am i getting this error, plz do help me in this problem, because i have been trying to solve this problem for a long time but still no success.
- 01-12-2010, 02:14 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Don't add jsp-api.jar to your lib. Tomcat should have it's own already.
You should NOT add any jars in there that the container already has.
Then you need to post the full stacktrace you are getting.Last edited by r035198x; 01-12-2010 at 02:53 PM. Reason: NOT
- 01-12-2010, 02:50 PM #3
Member
- Join Date
- Aug 2009
- Posts
- 25
- Rep Power
- 0
If I don't include jsp-api.jar, then the tag handler class "DateTag.java" will have errors because it won't know who javax.servlet.jsp.JspException and others are...(I'm working in Eclipse).
My current error is:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: java.lang.NullPointerException
org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:522)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:356)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
root cause
java.lang.NullPointerException
org.apache.jsp.dateTag_jsp._jspInit(dateTag_jsp.ja va:31)
org.apache.jasper.runtime.HttpJspBase.init(HttpJsp Base.java:52)
org.apache.jasper.servlet.JspServletWrapper.getSer vlet(JspServletWrapper.java:159)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:329)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.
Thanks a lot!
- 01-12-2010, 02:57 PM #4
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
You should thus reference those jars from the tomcat directories from your eclipse or make sure that they are not exported during deployment.
Your tag doesn't make sense. What exactly is it supposed to do?
Why are you declaring NPE in the throws clause?
Do e.printStackTrace() when you catch an exception so that you get all the details of the exception.
- 01-12-2010, 03:04 PM #5
Member
- Join Date
- Aug 2009
- Posts
- 25
- Rep Power
- 0
I've added the NPE catch in disperation...
My tag is very simple, it should only show the current date...
I'm a beginner, I don't understand what you mean by the first line you wrote.
- 01-12-2010, 03:12 PM #6
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
In your IDE add the jsf-api.jars to your project's build path by referencing them from their tomcat directory locations. That way you don't duplicate jars on the classpath.
- 01-12-2010, 04:19 PM #7
Member
- Join Date
- Aug 2009
- Posts
- 25
- Rep Power
- 0
Thanks a lot, it finally worked...but I still haven't understood everything
You said:
"That way you don't duplicate jars on the classpath"
Why would I duplicate them?
- 01-12-2010, 05:43 PM #8
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Similar Threads
-
Jstl
By prakashkadakol in forum New To JavaReplies: 10Last Post: 01-13-2010, 07:17 PM -
Why are we using JSTL in jsp?
By makpandian in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 06-30-2009, 10:15 PM -
jstl tag <if>
By subha in forum Advanced JavaReplies: 1Last Post: 04-02-2009, 09:07 PM -
JSTL problem
By mihir66 in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 03-05-2009, 02:28 PM -
jstl in jsp
By nagaprasanna in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 11-18-2008, 08:18 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks