This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes Return static text in JSP Tag Libraries??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Return static text in JSP Tag Libraries???" Watch "Return static text in JSP Tag Libraries???" New topic
Author

Return static text in JSP Tag Libraries???

tuancan
Greenhorn

Joined: Jul 24, 2003
Posts: 2
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!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Return static text in JSP Tag Libraries???
 
Similar Threads
doAfterBody() is not executed using BodyTagSupport
TagSupport handler and fragment attribute
doInitBody()
pushBody() and popBody
Mock Exam Question - related to doAfterBody