JSP and JSTL Tutorials - Tutorial Addendum - JSP Custom Tag

wargamesios photoappsios games appcolt
 31 December 18:00   

    



    



    

(Continued from antecedent part...)

    



    

3. Autograph the tag library descriptor (tld) file. Now, I charge to ascertain a tag in a tag library

    

descriptor book to use the tag class. Actuality is my first tld file, HyTaglib.tld:

    

 

    

<?xml version="1.0"?>

    

<!DOCTYPE taglib Accessible

    

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

    

"http://java.sun.com/j2ee/dtds/web-jsptag library _1_2.dtd">

    

<!-- HyTaglib.tld

    

Absorb (c) 2003 by Dr. Yang

    

-->

    

<taglib>

    

<tlib-version>1</tlib-version>

    

<jsp-version>1.2</jsp-version>

    

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

    

<tag>

    

<name>hello</name>

    

<tag-class>HelloTag</tag-class>

    

<body-content>empty</body-content>

    

</tag>

    

</taglib>

    



    



    

4. Installing the tld file. Tag library descriptor files charge to be attainable

    

by the bobcat server. So I affected HyTaglib.tld to

    

localjakarta-tomcat-4.1.18webapps
ootweb-inf lds directory.

    



    

5. Autograph the JSP page. To use my first custom tag, I wrote the afterward

    

JSP page, hello_tag.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">

    

<!-- hello_tag.jsp

    

Absorb (c) 2003 by Dr. Yang

    

-->

    

<jsp:directive.page import="HelloTag"/>

    

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

    

<html><body>

    

<hy:hello/>

    

</body></html>

    

</jsp:root>

    



    



    

6. Examination the JSP page. To see the achievement of my JSP page, I affected hello_tag.jsp

    

to localjakarta-tomcat-4.1.18webapps
oot, started bobcat 4.1.18 server, and

    

use Internet Explorer (IE) to appearance http://localhost:8080/hello_tag.jsp.

    



    

7. I did get the "Hello world!" bulletin in the IE window. So my accost tag formed perfectly.

    



    

8. If you are alteration your tag chic afterwards it has been loaded by tomcat,

    

you may charge to restart tomcat, or bang "restart" on the "root" appliance

    

on the bobcat admin page. "root" appliance is area I put my JSP pages.

    



    

How Custom Tag Works

    



    

Here is my compassionate of how custom tag works, using the "Hello world!" tag as

    

an example:

    



        

  • When "hello_tag.jsp" page is requested for the first time, Bobcat server will

        

    translate the JSP page into a java class.

        



  •     

  • When the <hy:hello/> custom tag is encountered during the translation,

        

    Tomcat server will chase the tld book to locate the HelloTag.class file.

        

    Note that the tld book is provided in the "jsp:root" element.

        



  •     

  • Then Bobcat server will alter the custom tag with some Java cipher

        

    to instantiate an item of the tag class, initialize the object, and alarm

        

    the doStartTag() method.

        



  •     

  • To achievement data into page, you can get an achievement beck from the

        

    pageContext item provided by the JSP tag addendum facility, pageContext.getOut().

        

    This is how the "Hello world!" bulletin gets produced in the IE window.

        



  •     

  • Note that I accept to use "jsp:directive.page" to acceptation HelloTag chic into

        

    the JSP page, because my HelloTag chic has no Java amalgamation name and needs

        

    to be imported, even if it is amid in the chic path.

        



  •     



    



    



    

 


Tags: world, server, class, custom, library, notes, tutorial, tutorials, object

 class, tomcat, custom, version, server, hellotag, hytaglib, world, object, output, directive, library, taglib, , jsp page, custom tag, < jsp, tag class, tld file, tag jsp, tomcat server, hytaglib tld, html <, hellotag class, directive page, server will, < body, tag library, < tag, jsp root, jsp directive, tomcat server will, jsp directive page, tag library descriptor, 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 ...

Permalink
Article In : Computers & Technology  -  jsp