aspose file tools
The moose likes JSP and the fly likes Return static text in JSP Tag Libraries??? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSP
Reply 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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Return static text in JSP Tag Libraries???
 
Similar Threads
doAfterBody() is not executed using BodyTagSupport
Mock Exam Question - related to doAfterBody
TagSupport handler and fragment attribute
doInitBody()
pushBody() and popBody