Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java for the WWW November 2012Slide Tag Libraries What are they? –Custom libraries Custom tags – see examples in following slides.

Similar presentations


Presentation on theme: "Java for the WWW November 2012Slide Tag Libraries What are they? –Custom libraries Custom tags – see examples in following slides."— Presentation transcript:

1 Java for the WWW November 2012Slide 1j.c.westlake@staffs.ac.uk Tag Libraries What are they? –Custom libraries Custom tags – see examples in following slides –Standard Tag Library (JSTL) – recommend that you read the following: http://today.java.net/pub/a/today/2003/10/07/jstl1.html http://today.java.net/pub/a/today/2003/11/27/jstl2.html Purpose and benefits for JSP web development –Lot of development and includes the AJAX technology but this is outside the scope of this moduleAJAX technology For further reading on Tag libraries – here is nice tutorial to back up the following notes link

2 Java for the WWW March 2009Slide 2j.c.westlake@staffs.ac.uk Custom tags Custom tags are dynamic page elements. This means they can provide functionality to a web page using a syntax similar to normal HTML tags. The functionality is up to you… They can provide an alternative (or an additional) mechanism to JavaBeans for dynamic scripting.

3 Java for the WWW March 2009Slide 3j.c.westlake@staffs.ac.uk What do you need? There are two components to a tag: –A Java tag handler class that implements the tag’s functionality. –A Tag Library Descriptor (TLD) in the form of an XML file describing the tag. By including this tag on a JSP page you have access to its functionality.

4 Java for the WWW March 2009Slide 4j.c.westlake@staffs.ac.uk Java handler class Yes, you have to code the functionality in Java. So why bother? Why not just create a JavaBean instead? –For standard web page scripters, tags are more familiar and provide a simpler mechanism. –For web application developers, JavaBeans integrate more fully with the full application environment so are more powerful. Your choice….

5 Java for the WWW March 2009Slide 5j.c.westlake@staffs.ac.uk Making the handler You Java class needs to extend the TagSupport class. This class is only available in the Enterprise version of the Java Development Kit (from version 1.3.1). Or, the Java Web Services Developer Pack. However, you just need the lib/j2ee.jap file (in the case of J2EE) or the lib/servlet.jar for the JWSDP. You can then extract the javax.servlet.jsp.tagext class from the.jar file (using WinZip etc.) and put it into folder containing your tag classes – see screen grab on next powerpoint

6 Java for the WWW March 2009Slide 6j.c.westlake@staffs.ac.uk

7 Java for the WWW March 2009Slide 7j.c.westlake@staffs.ac.uk Making the handler Once you have your custom tag Java code, you need to compile it and put the resultant.class file in your WEB-INF/classes folder. For the examples, this would go in: –WEB-INF/classes/mytags

8 Java for the WWW March 2009Slide 8j.c.westlake@staffs.ac.uk Example handler

9 Java for the WWW March 2009Slide 9j.c.westlake@staffs.ac.uk Tag Library Descriptor A TLD is a (fairly) simple XML file that describes a set of custom tags. You can put as many or as few custom tags in a TLD and more than one TLD can be used in a single project. In principle, you could create many useful tags and zip them into one.jar file for easy re- usability.

10 Java for the WWW Slide 10j.c.westlake@staffs.ac.uk Example Tag Descriptor

11 Java for the WWW March 2009Slide 11j.c.westlake@staffs.ac.uk Using your custom tag To use your custom tag, you need a JSP page. You need to tell your JSP where to find your tag library so you use a page directive: Anywhere in your JSP page, you can then use your custom tag(s):

12 Java for the WWW March 2009Slide 12j.c.westlake@staffs.ac.uk Example with a JSP

13 Java for the WWW March 2009Slide 13j.c.westlake@staffs.ac.uk Running tag examples Hello tag example link Formatting example link Date tag example link Formatted Date example link

14 Java for the WWW March 2009Slide 14j.c.westlake@staffs.ac.uk The use of tag libraries is all about... Re-usability Defining things once and making them available for use in more than one place Simplification Bespoke JSP work Or using existing tag libraries available for use - See the following Jsptags.com Jspin Jakata Apache Jakata Apache Taglibs project


Download ppt "Java for the WWW November 2012Slide Tag Libraries What are they? –Custom libraries Custom tags – see examples in following slides."

Similar presentations


Ads by Google