• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getBodyContent returns unjustified null ;-)

 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good day,
Here is a simple example of the BodyTagSupport class that should print the body content, using the getBodyContent method. getBodyContent returns here null, even though the body content exists in the corresponding JSP file.
I'm using WL 6.0 SP2.
Any ideas,
Dan
package tagext;
import java.io.IOException;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
public class HelloTag extends BodyTagSupport {

public int doStartTag() throws JspTagException {
return EVAL_BODY_INCLUDE;
}
public int doEndTag() throws JspTagException {
BodyContent b = getBodyContent();
if (b != null) {
String s = new String (b.getString());
try {
pageContext.getOut().write(s);
} catch (IOException ex) {}

}
return SKIP_PAGE;
}
}
 
Peter Masreblta
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Try to return EVAL_BODY_BUFFERED in the method doStartTag.
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No luck, it didn't even compile.
 
Peter Masreblta
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Look like WebLogic 6.0 does not support Java JSP API 1.2 yet.
You can use EVAL_BODY_TAG for now, which is deprecated as of Java JSP API 1.2.
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter,
When using EVAL_BODY_TAG I get a runtime error -
javax.servlet.jsp.JspTagException: Since tag class tagext.HelloTag does not implements BodyTag, it cannot return BodyTag.EVAL_BODY_TAG
at jsp_servlet._hello._jspService(_hello.java:106)
But HelloTag extends BodyTagSupport, which implements BodyTag.
Weird, isn't it?
Dan
 
ruijin yang
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Dan,
Please download Tomcat 4.0 and just change EVAL_BODY_INCLUDE to
EVAL_BODY_BUFFERED.Everything is Ok!
ruijin yang
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all!
The following works -
package tagext;
import java.io.IOException;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
public class HelloTag extends BodyTagSupport {

public int doEndTag() throws JspTagException {

BodyContent b = getBodyContent();
if (b != null) {
String s = new String (b.getString());
try {
pageContext.getOut().write(s);
} catch (IOException ex) {}

}
return SKIP_PAGE;
}
}
 
Dave Wingate
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Update for Tomcat 6 ... If you want to use EVAL_BODY_BUFFERED as (wisely) suggested above, you may need to grant this permission in your catalina.policy file:

permission java.util.PropertyPermission "org.apache.jasper.runtime.BodyContentImpl.LIMIT_BUFFER", "read";
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic