Java Tutorial - Java Script : JSP Standard Tag Library

Java Tutorial - Java Script :

JSP Standard Tag Library

JSTL tags are called actions, in recognition of the fact that they generate dynamic web content. Like XML elements, actions can stand alone (<tagname/>) or be paired (<tagname></ tagname>).The c:out action displays the contents of the local or instance variable indicated by its value attribute. The variable is specified using JSTL’s Expression Language, a simple data-access syntax that borrows from ECMAScript (JavaScript) and XPath. Statements that use the language are contained within “${“ and “}” characters. In the preceding example, the variable param is one of several standard Expression Language variables that contain information about the page, web application, and servlet container. The param variable is a collection that holds all of the page parameters, each represented as a string. The rest of the page contains three core actions used to create a conditional block:
<c:choose>
<c:when test=’${!empty param.name}’>
<h2>Hello, <c:out value=’${param.name}’/></h2>
</c:when>
<c:otherwise>
<h2>Hello, stranger</h2>
</c:otherwise>
</c:choose>
The c:choose-c:when-c:otherwise block mirrors the functionality of a switch-casedefault Java statement, displaying enclosed HTML output only for the first c:when action that has a test attribute with the value true. If none of the actions is true, the c:otherwise contents are displayed. JSTL is composed of five tag libraries:
·         The core library (prefix c, default URI http://java.sun.com/jsp/jstl/core) contains general features: output, conditional display of content, looping, variable creation in several scopes, JavaBeans access, exception handling, URL imports, and URL redirection.
·         The SQL library (prefix sql, default URI http://java.sun.com/jsp/jstl/sql) covers database access: data source selection, queries, updates, transactions, and looping through results.
·         The internationalization and formatting library (prefix fmt, default URI http://java.sun.com/jsp/jstl/fmt) offers these actions: locale and resource bundle use, text localization, and number and date formatting.
·         The XML processing library (prefix x, default URI http://java.sun.com/jsp/jstl/xml) supports XML: parsing, XPath access, XSLT transformation, looping through nodes, and conditional processing.
The function library (prefix fn, default URI http://java.sun.com/jsp/jstl/functions) contains useful functions to manipulate strings and collections.
The Expression Language has operators to retrieve information from instance variables (${object.varName}), data structures (${object[“name”]}), and indexed arrays or lists (${object[1]}). There also are operators for arithmetic (“+”, “-”, “*”, “/”, and “%”), comparisons (“==”, “!=”, “<”, “<=”, “>”, and “>=”), logic (“&&”, “||”, and “!”), and empty, which detects null objects and empty strings or collections. Parentheses can be used to group subexpressions.The language offers automatic type conversion and five kinds of literals: strings, which are enclosed within single or  double quotes, integers, floating-point numbers, boolean values (true or false), and null. There are seven special variables available in any expression:
·         cookie, a collection of all request cookies, each as an instance of the Cookie class from the javax.servlet.http package
·         header, a collection of all request headers, each as a string
·         headerValues, a collection of all request headers, each as a string array
·         initParam, a collection of all application initialization parameters, each as a string
·         pageContext, an instance of jspPageContext from the javax.servlet package
·         param, a collection of all request parameters, each as a string