天天看點

java 自定義tag_java自定義标簽(Java custom tag).doc

java自定義标簽(Java custom tag)

java自定義标簽(Java custom tag)

2009-04-10 11:27 what is the custom tag? On the JSP page, developed by the users in the form of tags to realize java code operation

Features: 1. classification: element tag labelling of containers

2. must be shut down properly

3. are not allowed to have the same name attribute, but there can be no property can also be

The 4. attribute is the name and value of the collection

A: the tag handler class: package call in the JSP page java code

There are two class a interface

The interface of tag and tagsupport bodytagsupport, the parent class

Tagsupport class inheritance

The tag class file:

Package com.lll.tag;

Import java.io.IOException;

Import javax.servlet.jsp.JspException;

Import javax.servlet.jsp.PageContext;

Import javax.servlet.jsp.tagext.Tag;

Import javax.servlet.jsp.tagext.TagSupport;

Public class XianShi extends {TagSupport

Private String username;

Private String pwd;

Public String (getPwd) {

Return pwd;

}

Public void setPwd (String PWD) {

This.pwd = pwd;

}

Public String (getUsername) {

Return username;

}

Public void setUsername (String username) {

This.username = username;

}

PageContext pc=null; / / pagecontext object statement

/ * *

The fourth step after the end of the label content

* /

Public int doEndTag (throws JspException) {

Auto-generated method stub / / TODO

Return TagSupport.EVAL_PAGE; / / return value according to look at the label after the end of how to carry out other code

}

/ * *

The start of the third step label to execute

* /

Public int doStartTag (throws JspException) {

{try

(pc.getOut).Print (username: +username);

Catch (IOException E) {}

Auto-generated catch block / / TODO

(e.printStackTrace);

}

Return; TagSupport.EVAL_PAGE; / / return value according to look at the label after the end of how to carry out other code

}

/ * *

The fifth step to release resources

* /

Public void (release) {

Auto-generated method stub / / TODO

(super.release);

}

/ * *

Set the page context first step

* /

Public void setPageContext (PageCo