JSP and JSTL Tutorials - Tutorial Addendum - JSP Tag Java Interface

lifestyleappsios windows appcolt educationappsios
 31 December 18:00   




(Continued from antecedent part...)



Implenting BodyTag Interface - TraceTag.java



In adjustment to affirm my compassionate of the IterationTag interface, I wrote


the afterward tag chic to book a abbreviate bulletin from anniversary implemented method


to appearance if it is called. I aswell acclimated a actual simple argumentation in doAfterTag()


to force the tag physique getting evaluated twice.






* TraceTag.java


* Absorb (c) 2003 by Dr. Yang. All rights reserved.




package ;


import java.io.*;


import javax.servlet.jsp.*;


import javax.servlet.jsp.tagext.*;


public chic TraceTag accouterments IterationTag {


clandestine boolean stop = false;


clandestine PageContext pc = null;


clandestine Tag t = null;


accessible abandoned setPageContext(PageContext pc) {


this.pc = pc;


println("setPageContext() called.");




accessible abandoned setParent(Tag t) {


this.t = t;


println("setParent() called.");




accessible Tag getParent() {


println("setParent() called.");


acknowledgment t;




accessible abandoned setMyAtt(String v) {


println("setMyAtt() called.");




accessible int doStartTag() {


println("doStartTag() called.");


acknowledgment EVAL_BODY_INCLUDE;




accessible int doAfterBody() {


println("doAfterBody() called.");


if (!stop) {


stop = true;


acknowledgment EVAL_BODY_AGAIN;


} abroad {


acknowledgment SKIP_BODY;






accessible int doEndTag() {


println("doEndTag() called.");


acknowledgment EVAL_PAGE;




accessible abandoned release() {


println("release() called.");




clandestine abandoned println(String s) {


try {




} bolt (IOException e) {












In this tag class, I was planning to accept one aspect for my trace tag. Attributes


of a tag charge to be implemented as backdrop in the tag class. The setMyAtt(String v)


method ascertain a acreage alleged "myAtt" for my trace tag.



After accumulation my trace tag class, I affected TraceTag.class to


ootweb-infclasses directory.


I had to put it beneath subdirectory "", because the tag chic was


define in "" package.



Then I adapted my tld file, HyTaglib.tld, with a new tag element:




<?xml version="1.0"?>


<!DOCTYPE taglib Accessible


"-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"




<!-- HyTaglib.tld


Absorb (c) 2003 by Dr. Yang










<short-name> s Tag Library</short-name>




















<!-- additional tags -->






Since my trace tag will accept body, I set body-content to "jsp" instead of "empty".


The adapted tld book was affected to


ootweb-inf lds directory.



To analysis my trace tag, I wrote the afterward JSP page, TraceTagTest.jsp:




<?xml version="1.0"?>


<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"




xmlns:hy="urn:jsptld:/WEB-INF/tlds/HyTaglib.tld" version="1.2">


<!-- TraceTagTest.jsp


Absorb (c) 2003 by Dr. Yang




<jsp:directive.page contentType="text/html"/>




<hy:trace myAtt="my value">


<jsp:text>JSP body</jsp:text><br/>










Note that I did not use jsp:directive.page to acceptation my trace tag class,


because the chic in now beneath "" package.



I put the JSP page on my bobcat server, and restarted the server. If


requesting this JSP page with IE, I got the afterward output:




setPageContext() called.


setParent() called.


setMyAtt() called.


doStartTag() called.


JSP body


doAfterBody() called.


JSP body


doAfterBody() called.


doEndTag() called.




The achievement was absolutely what I expected. The JSP was absolutely evaluated twice


as controlled by the abiding banderole of doAfterBody().


One surpprise is that there was no alarm to release().


I don t understand why.


(Continued on next part...)




Tags: class, content, called, package, attribute, release, interface, notes, public, trace, string, short, tutorial, tutorials

 called, println, class, public, trace, version, return, setmyatt, tracetag, interface, setparent, private, import, hytaglib, tomcat, following, xmlns, taglib, attribute, content, dostarttag, short, setpagecontext, copyright, string, package, doendtag, doafterbody, release, , tag class, trace tag, < jsp, jsp page, public void, name <, html <, < tag, < body, sun com, hytaglib tld, called return, setparent called, public int, return eval, http java, jsp tag, java sun, return eval body, jsp directive page, jsp bodydoafterbody called, called return eval, println setparent called, tutorials tutorial notes, tag java interface, import javax servlet, jstl tutorials tutorial,

Share JSP and JSTL Tutorials - Tutorial Addendum - JSP Tag Java Interface:
Digg it!   Google Bookmarks   Del.icio.us   Yahoo! MyWeb   Furl  Binklist   Reddit!   Stumble Upon   Technorati   Windows Live   Bookmark

Text link code :
Hyper link code:

Also see ...

Article In : Computers & Technology  -  jsp