Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

getBodyContent returns unjustified null ;-)

 
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;
}
}
 
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
 
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;
}
}
 
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";
 
He's my best friend. Not yours. Mine. You can have this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic