Monday, November 16, 2009

JSTL Tags (part - 1)


JSTL tags
The JSTL 1.1 API Specification consists of following packages:
Tag
Description
Core (javax.servlet.jsp.jstl.core)
General purpose actions
Format (javax.servlet.jsp.jstl.fmt)
Internationalization and Localization
SQL (javax.servlet.jsp.jstl.sql)
Common database tasks
Tag Library Validator(javax.servlet.jsp.jstl.tlv)
Tag Library Validators
Description of JSTL Tags
Core Tags: 
These tags provides the core functionality that a programming language is supposed to provide, such as codition, iteration etc.
1). <c:out>
This tag is used to evaluate an expression and output the result to the current JspWriter object.
Syntax: <c:out value="value" [escapeXml="{true|false}"]  [default="defaultValue"] />
2). <c:forEach>
This tag provide functionality to iterate over an array or collection without using java code.
Syntax: <c:forEach [var="varName"] items = "collection"  [varStatus="varStatusName"] [begin="start"] [end="end"] [step="step"]>
   .... body..
</c:forEach>

3.) <c:if>
This is used for conditional branching within the jsp page based on some test.
Syntax: <c:if  test ="testCondition" var="varName" [scope="{page|request|session|application}"] />
4). <c:set>
This tag is used to set attributes within specified scopes in jsp pages
Syntax: <c:set value="val" var="varname" [scope="{page|request|session|application}"] />
5).  <c:remove>
This tag is used to remove a scoped variable.
Syntax: <c:remove var="varName" [scope="{page|request|session|application}"] />
6).  <c:url>
This tag is used for session management and URL rewriting.
Syntax: <c:url value="value" [context="context"] [var="varName"] [scope="{page|request|session|application}"] />
7).  <c:import>
This is used to include external resources inside the jsp page.
<c:choose>, <c:when> and <c:otherwise> tags
These tags are used for conditional branching, that is provided by switch.... case statement in most programming languages. <c:choose> is used for mutually exclusive conditional execution.
Syntax: <c:choose>..body..... (<when> and <otherwise> subtags) </c:choose>
<c:when> represents an alternative within a <c:choose> action.
Syntax: <c:when test="testCondition">  .... body </c:when>
<c:otherwise> represents the last alternative within a <c:choose> action.
Syntax: <c:otherwise> ..... conditional block..</c:otherwise>
8).  <c:catch>
This tag provide a try...catch like mechanism inside jsp pages without using scriptlets.
Syntax: <c:catch [var="varName"]> .... nested actions </c:catch>
9).  <c:redirect>
This provides same functionality as the sendRedirect() method of HttpServletRequest interface. It is used to redirect control to other pages within the web application.
Syntax: <c:redirect url="value" [context="context"] />
10).  <c:param>
This tag is used to add request parameters to a URL. It is also used as a nested tag, within the <c:import>, <c:url> and <c:rediret> tags.
Syntax: <:param name = parameterName" value = "parameterValue" />
11).  <c:forEachToken>
This tag when provided with delimiters can be used to iterate over tokens. Its functionality is like that of StringTokenizer.
Syntax: <c:forTokens items = "tokenString" delims="delimiter"
            [var="variableName"] [varStatus="variableStatusName"] [begin="start"  [end="end"]  [step="step"]> ........ body content..</c:forTokens>

Stumble
Delicious
Technorati
Twitter

0 Comments:

Post a Comment