<document>
<deftable>
The jsp page that uses the tags
The basic tag.
</deftable>

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.

<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 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.

<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> <results> A sample tag: Test 1<br> A sample tag: Test 2 </results>
</document>