📄 infotagbodyexample.java
字号:
package edu.jsp.tag;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.Writer;
import java.io.IOException;
public class InfoTagBodyExample extends BodyTagSupport
{
String userName;//对应于自定义标签的userName属性
int count;//对应于自定义标签的count属性
public InfoTagBodyExample()
{
super();
}
/**
*设置userName属性。这个方法由容器自动调用。
*/
public void setUserName(String user)
{
this.userName=user;
}
/**
*设置count属性。这个方法由容器自动调用。
*/
public void setCount(int count)
{
this.count=count;
}
/**
*覆盖doStartTag方法
*/
public int doStartTag() throws JspTagException
{
System.out.println("doStartTag");
if(count>0) {
return EVAL_BODY_TAG;
}
else {
return SKIP_BODY;
}
}
/**
*覆盖doAfterBody方法
*/
public int doAfterBody() throws JspTagException
{
System.out.println("doAfterBody");
if (count-- >= 1) {
try {
JspWriter out = bodyContent.getEnclosingWriter();
out.println(bodyContent.getString() + userName);
out.println("<br>");
bodyContent.clearBody(); // Clear for next evaluation
} catch(IOException ioe) {
System.out.println("Error in RepeatTag: " + ioe);
}
return(EVAL_BODY_TAG);
} else {
return(SKIP_BODY);
}
}
/**
*覆盖doEndTag方法
*/
public int doEndTag() throws JspTagException
{
System.out.println("doEndTag");
return EVAL_PAGE;
}
public void doInitBody() throws JspTagException
{
System.out.println("doInitBody");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -