• 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Return static text in JSP Tag Libraries???  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just have started in studying JSP Tag Libraries. I write a tag lib just return static content's body of tag to user. I tried to write as below:
package com.tagLibs;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
public class readBodyOfTag extends BodyTagSupport {
public int doAfterBody() throws JspException {
return EVAL_BODY_INCLUDE;
}
}
But it could not run, compiling is OK. It didn't show any error.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
When I tried as below:
package com.tagLibs;
import java.io.StringWriter;
import java.io.PrintWriter;
import java.io.IOException;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
public class readBodyOfTag extends BodyTagSupport {
public int doAfterBody() throws JspException {
try {
BodyContent body = getBodyContent();
JspWriter writer = body.getEnclosingWriter();
String bodyString = body.getString();
if (bodyString != null) {
writer.println(bodyString);
}
}
catch (IOException ioe) {
throw new JspTagException("Error: IOException while writing to the user!");
}
return SKIP_BODY;
}
}
It works well. But I don't know why I must write a lot of code just for return static content's body of tag to user.
Can anybody tell me why the first code can not run? Thx a lot!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!