useridtag.java

来自「It gives some some of examples of java s」· Java 代码 · 共 73 行

JAVA
73
字号
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 + =
减小字号Ctrl + -
显示快捷键?