JSP and JSTL Tutorials - Tutorial Addendum - JSP Custom Tag

wargamesios photoappsios games appcolt
 31 December 18:00   





What is a Custom Tag?



Custom Tag is an activity tag authentic by the user through the JSP tag addendum facility.


It can be acclimated to move JSP page assembly logics and advice into a tag Java class, and invoke


it by an activity tag that is affiliated to that class. There are two capital advantages of using


custom tags:



  • Repeatable JSP page logics and advice can be simplified and centralized into a individual tag.


    For example, we can ascertain a custom tag alleged <my:copyright/> for bearing


    the absorb advice that charge to be acclimated on every page of server.



  • Moving circuitous business logics from the JSP to a tag class, so the JSP page


    author can apply on the presentation logics only. For example, we can ascertain a


    custom tag alleged <my: user List/> for bearing a HTML table abounding with a account of user s.


    The tag chic will administer how the put anniversary user into a row, and anniversary user acreage


    into a column.





I am abiding that the functionalities provided by custom tags can aswell be archived by


using JavaBean and scripting elements together. But tags assume to be simpler to use


for some artless JSP page authors.



"Hello world!" Custom Tag



Before we go into any abstruse details, let me use a actual simple archetype to appearance


you the accomplish to ascertain and use a custom tag.


I wish to ascertain a tag alleged <hy:hello/> to aftermath the "Hello world!" in the calling


JSP page.



1. Autograph the tag class. Actuality is my first tag class, HelloTag.java, which extends


the TagSupport chic provided in the JSP package:






* HelloTag.java


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




import java.io.*;


import javax.servlet.jsp.tagext.*;


public chic HelloTag extends TagSupport {


accessible int doStartTag() {


try {


pageContext.getOut().write("Hello world!");


} bolt (IOException e) {






acknowledgment SKIP_BODY;








2. Installing the tag class. I aggregate HelloTag.java with JDK 1.3.1, and servlet.jar


provided by the Bobcat 4.1.18 server. Like the JavaBean chic files, tag chic files


also charge to be installed in the chic aisle of the bobcat server. So I affected


the HelloTag.class to localjakarta-tomcat-4.1.18webapps
ootweb-infclasses directory.


(Continued on next part...)




Tags: information, world, example, server, class, custom, called, provided, notes, tutorial, tutorials

 class, custom, hellotag, logics, define, world, tomcat, provided, called, information, example, copyright, server, , custom tag, tag class, jsp page, hellotag java, tag called, called <, tutorials tutorial notes, jstl tutorials tutorial,

Share JSP and JSTL Tutorials - Tutorial Addendum - JSP Custom Tag:
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