SunQuest
 
       Java
  Home arrow Java arrow Page 4 - The JSP Files (part 8): Tagged And Bag...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
VeriSign Whitepapers 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

The JSP Files (part 8): Tagged And Bagged
By: Vikram Vaswani and Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 5
    2001-06-11

    Table of Contents:
  • The JSP Files (part 8): Tagged And Bagged
  • Playing Tag
  • Looking Inside
  • Meeting Popeye
  • You've Got Mail!
  • Applet Antics

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
    IBM developerWorks
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    The JSP Files (part 8): Tagged And Bagged - Meeting Popeye


    (Page 4 of 6 )

    At this point, you can begin using the new tag library in your JSP pages. First, declare it with the "taglib" directive - this directive must appear before any custom tags in the page.


    <%@ taglib uri="http://jakarta.apache.org/taglibs/datetime-1.0" prefix="popeye" %>
    The URI is the unique identifier for the tag library, and must match the URI specified in "web.xml", while the prefix appears in every call to a custom tag, and is used to distinguish between tags from different libraries in the same page.

    Once the library has been declared, you can begin using custom tags in your JSP scripts. Consider the following example, which uses a custom tag from the DATETIME library to calculate the number of seconds elapsed since January 1 1970.

    <html> <head> </head> <body> <%@ taglib uri="http://jakarta.apache.org/taglibs/datetime-1.0" prefix="popeye" %> The number of milliseconds since January 1, 1970 is <popeye:currenttime/> </body> </html>
    And the output is:

    The number of milliseconds since January 1, 1970 is 987165837280
    What if you simply want the current date and time? By combining the <currenttime> tag with the <format> tag, the DATETIME library makes it a snap!

    <html> <head> </head> <body> <%@ taglib uri="http://jakarta.apache.org/taglibs/datetime-1.0" prefix="popeye" %> The current date and time is <popeye:format pattern="hh:mm EEE MMMM dd yyyy"> <popeye:currenttime/> </popeye:format> </body> </html>
    In case you're wondering, the EEEs and MMMs you see there are formatting codes, used to define the format in which the date and time is to be printed. Here's the output:

    The current date and time is 06:22 Fri April 13 2001
    The example above also illustrates how some tags can be nested within one another - this can make for powerful combinations, and is one of the clever things about this architecture.

    How about generating a list of days or months? The DATETIME library's got you covered with its <weekdays> and <months> tags...

    <html> <head> </head> <body> <%@ taglib uri="http://jakarta.apache.org/taglibs/datetime-1.0" prefix="popeye" %> <form> Select a day <select name="weekday"> <popeye:weekdays id="day"> <option value="<jsp:getProperty name="day" property="dayOfWeek"/>"> <jsp:getProperty name="day" property="weekday"/> </popeye:weekdays> </select> </form> </body> </html>
    The DATETIME library comes with a whole bunch of other useful tags too - take a look at the documentation to see the various other features available.

    More Java Articles
    More By Vikram Vaswani and Harish Kamath, (c) Melonfire


     

       

    JAVA ARTICLES

    - Adding Images With iTextSharp
    - Adding Columns With iTextSharp
    - Creating Simple PDF Files With iTextSharp
    - The Spring Framework: Understanding IoC
    - Introducing the Spring Framework
    - Java Classes
    - Completing the Syntactic Comparison of Java ...
    - Syntactic Comparison of Java and C/C++
    - Java Statements
    - Conditionals, Expressions and Other Java Ope...
    - Java Operators
    - Primitive Data Types and Basic Language Rule...
    - Java and Object-Oriented Programming
    - Java Beginning Programming
    - Gaming Development Setup

    Click Here




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway