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

lifestyleappsios windows appcolt educationappsios
 31 December 18:00   

    



    



    

(Continued from antecedent part...)

    



    

The Servlet Chic - TraceTagTest_jsp.java

    



    

As we all understand that JSP pages are translated into Servlet classes before

    

execution. So we infact analysis the construe Servlet chic to see how the

    

tag addendum ability connects the Servlet chic to the tag class.

    



    

To analysis the Servlet chic translated from TraceTagTest.jsp, accessible TraceTagTest_jsp.java

    

in localjakarta-tomcat-4.1.18workstandalonelocalhost\_, you will see:

    

 

    

package org.apache.jsp;

    

import javax.servlet.*;

    

import javax.servlet.http.*;

    

import javax.servlet.jsp.*;

    

import org.apache.jasper.runtime.*;

    

public chic TraceTagTest_jsp extends HttpJspBase {

    

clandestine changeless java.util.Vector _jspx_includes;

    

clandestine org.apache.jasper.runtime.TagHandlerPool

    

_jspx_tagPool_hy_trace_myAtt;

    

accessible TraceTagTest_jsp() {

    

_jspx_tagPool_hy_trace_myAtt

    

= new org.apache.jasper.runtime.TagHandlerPool();

    

}

    

accessible java.util.List getIncludes() {

    

acknowledgment _jspx_includes;

    

}

    

accessible abandoned _jspDestroy() {

    

_jspx_tagPool_hy_trace_myAtt.release();

    

}

    

accessible abandoned _jspService(HttpServletRequest request,

    

HttpServletResponse response)

    

throws java.io.IOException, ServletException {

    

JspFactory _jspxFactory = null;

    

javax.servlet.jsp.PageContext pageContext = null;

    

HttpSession affair = null;

    

ServletContext appliance = null;

    

ServletConfig config = null;

    

JspWriter out = null;

    

Item page = this;

    

JspWriter _jspx_out = null;

    

try {

    

_jspxFactory = JspFactory.getDefaultFactory();

    

response.setContentType("text/html;charset=UTF-8");

    

pageContext = _jspxFactory.getPageContext(this, request, response,

    

null, true, 8192, true);

    

appliance = pageContext.getServletContext();

    

config = pageContext.getServletConfig();

    

affair = pageContext.getSession();

    

out = pageContext.getOut();

    

_jspx_out = out;

    

out.write("<html>");

    

out.write("<body>");

    

if (_jspx_meth_hy_trace_0(pageContext))

    

return;

    

out.write("</body>");

    

out.write("</html>");

    

} bolt (Throwable t) {

    

out = _jspx_out;

    

if (out != absent && out.getBufferSize() != 0)

    

out.clearBuffer();

    

if (pageContext != null) pageContext.handlePageException(t);

    

} assuredly {

    

if (_jspxFactory != null)

    

_jspxFactory.releasePageContext(pageContext);

    

}

    

}

    

clandestine boolean _jspx_meth_hy_trace_0(

    

javax.servlet.jsp.PageContext pageContext)

    

throws Throwable {

    

JspWriter out = pageContext.getOut();

    

/* ---- hy:trace ---- */

    

.TraceTag _jspx_th_hy_trace_0 = (.TraceTag)

    

_jspx_tagPool_hy_trace_myAtt.get(.TraceTag.class);

    

_jspx_th_hy_trace_0.setPageContext(pageContext);

    

_jspx_th_hy_trace_0.setParent(null);

    

_jspx_th_hy_trace_0.setMyAtt("my value");

    

int _jspx_eval_hy_trace_0 = _jspx_th_hy_trace_0.doStartTag();

    

if (_jspx_eval_hy_trace_0 !=

    

javax.servlet.jsp.tagext.Tag.SKIP_BODY) {

    

do {

    

out.write("JSP body");

    

out.write("<br/>");

    

int evalDoAfterBody = _jspx_th_hy_trace_0.doAfterBody();

    

if (evalDoAfterBody !=

    

javax.servlet.jsp.tagext.BodyTag.EVAL_BODY_AGAIN)

    

break;

    

} while (true);

    

}

    

if (_jspx_th_hy_trace_0.doEndTag() ==

    

javax.servlet.jsp.tagext.Tag.SKIP_PAGE)

    

acknowledgment true;

    

_jspx_tagPool_hy_trace_myAtt.reuse(_jspx_th_hy_trace_0);

    

acknowledgment false;

    

}

    

}

    



    



    

As you can see, the absolute hy:trace aspect was translated into a adjustment call,

    

_jspx_meth_hy_trace_0(pageContext). In that method, an item was instantiated

    

from my trace tag class. Then interface methods were alleged one by one in the

    

same adjustment as we discussed in the antecedent section. The "do" bend was there

    

to amend the physique based on the abiding banderole of doAfterBody() call.

    



    

After finishing this trace tag example, I had a actual acceptable compassionate of

    

how the tag interface offered by the addendum ability works now. How about you?

    



    

Dummy Accomplishing of IterationTag Interface - TagSupport Class

    



    

J2EE supplied a copy implementation, alleged TagSupport, to the IterationTag interface.

    

If you are architecture a new tag class, you may extend your chic from TagSupport, instead

    

of apparatus InterationTag. Extending your tag chic from TagSupport gives you

    

two advantages.

    



    

1. Charge to cipher any appropriate method, if you are blessed with the accomplishing of

    

that adjustment central TagSupport.

    



    

2. TagSupport provides you the pageContext item accessible to use. No charge for you

    

to cipher setPageContext() and save it in your tag object.

    



    

Examples of using TagSupport will be cover in my additional addendum on custom tags.

    



    



    

 


Tags: class, write, method, interface, notes, public, trace, tutorial, tutorials, response, object

 trace, pagecontext, servlet, class, javax, tagsupport, write, interface, myatt, public, jspxfactory, tagpool, tracetagtest, object, method, import, apache, return, tagext, runtime, notes, tracetag, implementation, translated, private, jspwriter, jasper, response, , javax servlet, servlet jsp, jspx tagpool, trace myatt, tracetagtest jsp, write <, tag class, servlet class, org apache, jspx meth, jsp tagext, apache jasper, import javax, jasper runtime, jspx out, apache jasper runtime, import javax servlet, org apache jasper, jsp pagecontext pagecontext, class from tagsupport, jasper runtime taghandlerpool, tutorials tutorial notes, jstl tutorials tutorial, tag java interface,

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 ...

Permalink
Article In : Computers & Technology  -  jsp