JSP Standard Tag Library of JSP

How is JSP Standard Tag Library used in JSP?

Explanation

JSP Standard Tag Library (JSTL) was introduced to ease the programming in JSP by storing generic tasks in tag libraries under four different categories based on conditional processing and looping, XML processing, Internationalization and formatting, database access and a set of expression language functions.

Syntax:


<%@ taglib uri="URIToTagLibrary" prefix="tagPrefix" %>

In the above example the "uri" points to the tag library "matlib.tld", the prefix used in the taglib directive as well as in the coding is same that is "mtaglib".

The following table lists the URI for the JSTL 1.1 libraries.
Library URI Prefix
Core http://java.sun.com/jsp/jstl/core c
XML Processing http://java.sun.com/jsp/jstl/xml x
l18N formatting http://java.sun.com/jsp/jstl/fmt fmt
Database access http://java.sun.com/jsp/jstl/sql sql
Functions http://java.sun.com/jsp/jstl/functions fn

Example :


<%@ taglib uri="http://java.sun.com/jsp/jstl/core"
prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions"
prefix="fn" %>
<html>
<head><title>JSTL Functions</title></head>
<form>
USERNAME:<input type="text" name="usr" size="25">
<p></p>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
<br>
Length of your Username is::
<c:out value="${fn:length(param.usr)}" />

In the above example first taglib directive points to the JSTL core tag library with prefix "c". So the "<c:out" statement works fine. For the functions like "${fn:length(param.usr)}" that can be invoked using the JSP Expression Language we include the JSTL function library with prefix "fn". The above example outputs the length of the username entered.

Ask Questions

Ask Question