Mastering Resin

JSTL and JSP-EL Support

JSTL is a specification for a library of tags that provide a collection of common functionality to Web designers using JSP The JSTL specification can be found at http://java.sun.com/products/jsp/jstl/. The library was developed Some of the functionality provided in the tag library is:

The URIs for each type of functionality in the library are shown in Table 3.5.

Table 3.5: URls for JSTL Functionality

FUNTIONAL AREA

URI

PREFIX

Core

http://java.sun.com/jstl/core

c

XML processing

http://java.sun.com/jstl/xml

x

118N capable formatting

http://java.sun.com/jstl/fmt

fmt

Database access (SQL)

http://java.sun.com/jstl/sql

sql

The Resin 3.x server line supports the JSTL specification. With JSTL, we can do things like:

<c:if test="${!empty cookie.userName}"> Welcome back <c:out value="${cookie.userName.value}" /> </c:if>

Another important advance in the Resin 3.x server line is support for JSP-EL. JSP-EL is a simple language for accessing data in a JSP page. With JSP-EL, information can be stored in places like a pageContext or a request. For example:

<% boolean newUser = true; pageContext.setAttribute("userStatus", new Boolean(newUser)); %>

The stored variable can then be used later in the page:

<c:if test="${userStatus}"> User is new </c:if>

In the spirit of JSTL, Resin includes support for tag files as defined in JSP 2.0. For example, we might have a tag file defined as:

<%@ attribute name="a" type="java.lang.String" required="true" %> A sample tag: ${a}

The tag file should be used in a JSP file:

<%@ taglib prefix="x" tagdir="WEB-INF/tags" %> <X:test a="Test 1"/>

Категории