Tag FilesResin 3.0
Resin 3.0

Features
Installation
Configuration
Web Applications
IOC/AOP
Resources
JSP
Servlets and Filters
Portlets
Databases
Admin (JMX)
CMP
EJB
Amber
EJB 3.0
Security
XML and XSLT
XTP
JMS
Performance
Protocols
Third-party
Troubleshooting/FAQ

Introduction
JSP Compilation
Reference
Tutorials
Articles
FAQ

JSP Page Creation
Request
Topics
Tag Libraries

Tag Reuse
Hello Tag
Tag Attributes
Mail Tag
Tag Files
Mail Tag
Tag Libraries
Articles

Find this tutorial in: /usr/local/resin/webapps/resin-doc/jsp/tutorial/tagfile-basic
Try the Tutorial

JSP 2.0 introduces XML-based tag files. Instead of having to write Java code for custom tags, applications can use XML or JSP syntax for their tags. Tag files do not require .tld files, making development simpler.

  1. Files in this tutorial
  2. The tag file
  3. Using the tag file

Files in this tutorial

test.jsp The jsp page that uses the tags
WEB-INF/tags/test.tagx The basic tag.

The tag file

Tag files in JSP 2.0 look and run like normal JSP files with some extra directives. This example definine a tag attribute "a" which takes a String value. It prints a simple message.

See it in: WEB-INF/tags/test.tagx
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page">
  <jsp:directive.attribute name="a"
                           type="java.lang.String"
                           required="true"/>

  <jsp:text>A sample tag: ${a}</jsp:text>
</jsp:root>

The .tagx extension identifies the tag as a JSP tag file using XML syntax. The example could also have used test.tag for a tag file in JSP syntax. Tag files normally belong in WEB-INF/tags, although the location is configurable.

The tag example uses the JSP 2.0 Expression Language as an example and as a way to avoid any Java in the tag file. The ${a} tells the tag to look in the pageContext for a local variable a. The value of a is assigned by the tag attribute as defined in the attribute directive.

Using the tag file

Using tag files is similar to using normal JSP tags. This example uses the XML syntax, although normal JSP syntax would work, too. The namespace prefix urn:tagfiledir: tells JSP where to look for the tag. In this case it will look in WEB-INF/tags.

See it in: test.jsp
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
          xmlns:tags="urn:jsptagdir:/WEB-INF/tags">
  <tags:test a="Test 1"/><br/>
  <tags:test a="Test 2"/>
</jsp:root>

A sample tag: Test 1<br>
A sample tag: Test 2

Try the Tutorial


Mail Tag
Tag Libraries
Articles
Copyright © 1998-2005 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark, and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.