JSP and JSTL Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 3.09, 2006

JSTL - Core Library

Part:   1  2  3  4 

JSP/JSTL Tutorials - Herong's Tutorial Notes © Dr. Herong Yang

Using Cookies

Using JavaBean Classes

HTTP Response Header Lines

Non ASCII Characters

JSTL and Expression Language

File Upload

Execution Context

JSP Elements

JSP Standard Tag Libraries (JSTL)

JSP Custom Tag

... Table of Contents

JSTL Core Library

JSTL core library can be introduced to a JSP page with:

<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" 
   xmlns:c="http://java.sun.com/jstl/core" version="1.2"> 

It provides the following basic scripting functions:

<c:out value="..."/>
<c:set var="..." value="..."/>
<c:if test="...">body</c:if>
<c:choose>body</c:choose>
<c:forEach items="...">body</c:forEach>
<c:forTokens items="..." delims="...">body</c:forTokens>

c:out Action

<c:out value="text_mixed_with_expressions"/>

The "value" attribute will be evaluated and the resulting value will be converted into a string which will be inserted into the HTTP response. The c:out action serves similar purposes as the JSP expression element.

c:set Action

<c:set var="name" value="expression"/>

The "var" attribute specifies a variable name, which will be declared and assigned with the value resulted from the "value" attribute. The c:set action serves similar purposes as the Java assignment statement.

c:if Action

<c:if test="expression"/>
body
</c:if>

If the "test" attribute is evaluated to true, body will be processed. The c:if action serves similar purposes as the Java if statement.

c:choose Action

<c:choose>
 <c:when test="expression">
  body
 </c:when>
 <c:when test="expression">
  body
 </c:when>
 ...
 <c:otherwise>
  body
 </c:otherwise>
</c:choose>

The body of the first c:when action that has the "test" attribute evaluated to true will be processed. If all "test" attributes are evaluated to false, the body of the c:otherwise action will be processed. The c:choose action serves similar purposes as the Java if-else statement.

(Continued on next part...)

Part:   1  2  3  4 

Dr. Herong Yang, updated in 2006
JSP and JSTL Tutorials - Herong's Tutorial Notes - JSTL - Core Library