Results 1 to 8 of 8
  1. #1
    berlindutza is offline Member
    Join Date
    Aug 2009
    Posts
    25
    Rep Power
    0

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

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    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 03:53 PM. Reason: NOT

  3. #3
    berlindutza is offline Member
    Join Date
    Aug 2009
    Posts
    25
    Rep Power
    0

    Default

    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!

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    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.

  5. #5
    berlindutza is offline Member
    Join Date
    Aug 2009
    Posts
    25
    Rep Power
    0

    Default

    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.

  6. #6
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    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.

  7. #7
    berlindutza is offline Member
    Join Date
    Aug 2009
    Posts
    25
    Rep Power
    0

    Default

    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?

  8. #8
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    When you place jsp-api jars in your lib, they get added to the classpath and the classes get loaded when needed. That same jar is also present as part of tomcat's jars so another one also gets loaded. The results are not predictable.

Similar Threads

  1. Jstl
    By prakashkadakol in forum New To Java
    Replies: 10
    Last Post: 01-13-2010, 08:17 PM
  2. Why are we using JSTL in jsp?
    By makpandian in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 06-30-2009, 11:15 PM
  3. jstl tag <if>
    By subha in forum Advanced Java
    Replies: 1
    Last Post: 04-02-2009, 10:07 PM
  4. JSTL problem
    By mihir66 in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 03-05-2009, 03:28 PM
  5. jstl in jsp
    By nagaprasanna in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 11-18-2008, 09:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •