Custom tags to avoid placing java code inside the JSP page "scripting", so that the JSP page is able to concentrate only on the presentation logic.
- old "classic" where a developer has to adjust the flow, from start go to ?? , will evaluate the body or not, all done depending on the return value of overridden methods . instance of tag handler is reused, can't rely on constructor to do initialization, better to use setPageContext( ).
- now everything is done overriding just one method. simple tag model never reuse tag handler instances.
body content:
- in practice content is not processed at all
- JspWriter out=getJspContext().getOut();
- out.print(" ... ");
- getJSPBody.invoke(null);
- out.print(" ... ");
- Modify to process body content
- StringWriter writer=new StringWriter();
- getJSPBody.invoke( writer );
- String bodyContent=writer.toString();
.tld addresses to custom tag, so how to know about
- explicit "within web.xml"
- implicit "must contain the optional uri element"
- place the .tld in /WEB-INF or within one of its sub directory
- use a packaged file, which is placed in /WEB-INF/lib
with Java-based tags tag handler is a java class, where as with Jsp based tags the tag handler is a Jsp page.
Comments
Post a Comment