Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

TagHandler - Exception in doAfterBody()  RSS feed

 
Stefan Closs
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i trying a sample from the book CoreServlets and deploy in Tomcat 5. My own If - Tag. There are a Costum Tag called If with 3 inner Tags (condition, then, else).
In condition Tag line 39 in my doAfterBody() method i got a NULL-Pointer Exception. In this line are no code and my debugger says that every statemant are returned correct in that method.
Please help.

Here are the code and the Exception:

package de.stefanclos.taglib;

import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.*;
import javax.servlet.*;
import java.io.*;

public class ConditionTag extends BodyTagSupport {

public int doStartTag() throws JspTagException {
// �bergeordnetes If Tag suchen und �berpr�fen
IfTag parent = (IfTag)findAncestorWithClass(this, IfTag.class);
if(parent == null) {

// Falls kein �u�eres IfTag existiert Ausnahme werfen
throw new JspTagException("�u�eres IfTag ben�tigt");
}
return EVAL_BODY_BUFFERED;
}

public int doAfterBody() throws JspTagException {

IfTag parent = (IfTag)findAncestorWithClass(this, IfTag.class);

// String aus dem Body holen
BodyContent body = getBodyContent();
String eingabe = body.getString();

// auf boolean casten
boolean condition = makeBoolean(eingabe);

// Ausdruck im IfTag setzen
parent.setCondition(condition);
//line 39 - Exception
return EVAL_PAGE;
}

private boolean makeBoolean(String s) {
if(s.equalsIgnoreCase("true".trim()))
return true;
else
return false;
}
}
*********************************
*********************************
java.lang.NullPointerException
de.stefanclos.taglib.IfThenTag.doAfterBody(IfThenTag.java:39)
org.apache.jsp.sctag_jsp._jspx_meth_sctag_then_0(sctag_jsp.java:263)
org.apache.jsp.sctag_jsp._jspx_meth_sctag_if_0(sctag_jsp.java:196)
org.apache.jsp.sctag_jsp._jspService(sctag_jsp.java:96)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
 
Stefan Closs
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry i found the problem, i used EVAL_BODY_INCLUDE instead of EVAL_BODY_BUFFERED in my doStart() method so i got a NULL-pointer Exception on using the BodyContent Instance.

cheers,
Stefan Clos
-----------
SCJP
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!