📄 useridtag.java
字号:
package examples;import javax.servlet.jsp.tagext.*;import javax.servlet.jsp.*;import java.io.Writer;/** * Example2: A connection/query tag. * This is the userid entry. * * The data is stored up into the containing <connection> tag. * It is an error (currently only detected at run-time) not to have * a containing <connection> tag instance. * * <userId><%= some expr...%></userId> */public class UserIdTag extends BodyTagSupport { /** * Create a new UserIdTag */ public UserIdTag() { super(); } /** * Attributes for this action: * NONE */ /** * Process a start tag. * Find the enclosing connection tag and keep a reference aside. * * @return evaluate the body */ public int doStartTag() throws JspTagException { myConnection = (ConnectionTag) findAncestorWithClass(this, ConnectionTag.class); if (myConnection == null) { throw new JspTagException("userid must be inside a connection"); } return EVAL_BODY_TAG; } /** * After body evaluation. * Extract a string from the nested stream. * * @param body the BodyContent for this tag * @return SKIP_BODY */ public int doAfterBody() { BodyContent body = getBodyContent(); // Convert to String for use myConnection.setUserId(body.getString()); // Clean up body.clearBody(); // Do not reevaluate the body return SKIP_BODY; } // variables private ConnectionTag myConnection; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -