JSP TAG production

xiaoxiao2021-03-06  44

The basic steps:

1. First write the Class class, the Extends Tagsupport class, rewrite the methods you need.

(Note: If the SIMPLETAGSUPPORT class is inherited, the processing code must be placed in the dotag () method)

2. Configuration

Write a TLD file, configure the web.xml file

3.jsp call

Note: Tomcat comes with EXAMPLE is a good example of imitation

If the Class class inherits from SIMPLETAGSUPPORT, all operations are placed in the dotag () method;

If the Class class inherits from Bodytagsupport,

In the BodyTagSupport category, the dostartTag () preset is to return Eval_Body_buffered, then execute setbodycontent () and doinitbody () method, setBodyContent () sets the BodyContent object, which includes some tag body text information, write during processing label Out of the information to Response, you will enter the DOAFTERBODY () method after this, you can return to Eval_Body_again or Skip_Body, if the former is back, then the above process is executed again.

Inheriting the SIMPLETAGSUPPORT class can participate in the TAMCAT brought example.

Public class pagedivide extends bodytagsupport {

Public Iterator Iterator;

Public Object ELEMENT;

Public int desartTartTag () throws jspexception {

Try {

Database db = new database ();

db.init ();

Iterator = db.getcourse (). Itrator ();

} catch (exception e) {

E.PrintStackTrace ();

}

Ite (item.hasnext ()) {

ELEMENT = Iterator.next ();

PageContext.setttribute ("Course", Element);

}

RETURN EVAL_BODY_BUFFERED;

}

Public int doafterbody () {

Try {

BodyContent.writeout (this.getpreviousout);

} catch (ioexception e) {

E.PrintStackTrace ();

}

BodyContent.clearBody ();

Ite (item.hasnext ()) {

ELEMENT = Iterator.next ();

PageContext.setttribute ("Course", Element);

RETURN EVAL_BODY_AGAIN

Else

Return Eval_page;

}

}

转载请注明原文地址:https://www.9cbs.com/read-53843.html

New Post(0)