filtertag.java
来自「beginJsp2.0外文书籍源代码」· Java 代码 · 共 48 行
JAVA
48 行
package custom;
import java.util.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
public class filterTag extends BodyTagSupport
{
public int doStartTag()
{
return EVAL_BODY_BUFFERED;
}
public int doAfterBody() throws JspException
{
String cleanString = "";
BodyContent bc = getBodyContent();
// Get bc as a string
String unfiltered = bc.getString();
// StringTokenizer splits the string into tokens, using spaces as the
// delimiters
StringTokenizer st = new StringTokenizer(unfiltered);
while (st.hasMoreTokens())
{
String temp = st.nextToken();
// Censor if we find the dreaded word
if(temp.equalsIgnoreCase("drat"))
temp = "****";
// Add a space between each word
cleanString += " " + temp;
}
try
{
getPreviousOut().print(cleanString);
}
catch(Exception e)
{
throw new JspException(e.toString());
}
return SKIP_BODY;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?