top of page

JSTL core tags library

bodarmanali66

-The core group of tags are the most frequently used JSTL tags.

-the JSTL core tag provides variable support, URL management , flow control etc.

  • Syntax to include JSTL core library in your JSP:

1.

c:out

It display the result of an expression, similar to the way <%=..%> tag work.

E.g<c:out value="${'Welcome to JSTL'}" />

2.

c:import

It is similar to jsp 'include', with an additional feature of including the content of any resource either within server or outside the server.

E.g<c:import var="data" url="http://www.xyz.com"/>

3.

c:set

It is used to set the result of an expression evaluated in a 'scope'. This tag is similar to jsp:setProperty action tag.

E.g<c:set var="Income" scope="session" value="${4000*4}" />

4.

c:remove

It is used for removing the specified scoped variable from a particular scope.

E.g<c:set var="income" scope="session" value="${4000*4}" />

<c:remove var="income" />

5.

c:if

It is conditional tag used for testing the condition and display the body content only if the expression evaluates is true.

E.g<c:if test="${income > 8000}">

<p>My income is:<c:out value="${income}" /></p>

</c:if>

6.

c:catch

It is used for catching any Throwable exceptions that occurs in the body and optionally exposes it.

E.g<c:catch var="MyException">

<% int x=2/0; %>

</c:catch>

7.

c:choose

It is a conditional tag that establish a context for mutually exclusive conditional operations. It works like a Java switch statement in which we choose between a numbers of alternatives.

c:when

It is subtab of <choose> that will include its body if the condition evaluated be 'true'.

c:otherwise

It is also subtab of <choose> it follows <when> tags and runs only if all the prior condition evaluated is 'false'.

The <c:when> and <c:otherwise> works like if-else statement. But it must be placed inside <c:choose tag>.

E.g<c:choose>

<c:when test="${marks > 75}">

Congratulations ! You hold Distinction

</c:when>

<c:otherwise>

Sorry! Result is unavailable.

</c:otherwise>

</c:choose>

8.

c:forEach

It is an iteration tag used for repeating the nested body content for fixed number of times. The <c:forEach> tag is most commonly used tag because it iterates over a collection of object.

E.g<c:forEach var="i" begin="0" end="5">

count <c:out value="${i}" />

</c:forEach>

9.

c:forTokens

It iterates over tokens which is separated by the supplied delimiters.

E.g<c:forTokens items="DIET-Department" delims="-" var="name">

10.

c:url

This tag creates a URL with optional query parameters. It is used for url encoding or url formatting. This tag automatically performs the URL rewriting operation.

E.g<c:url value="/MyJspFile.jsp" />

11.

c:param

It allow the proper URL request parameter to be specified within URL and it automatically perform any necessary URL encoding.

E.g<c:param name="CollegeCode" value="054">

</c:param>

12.

c:redirect

This tag redirects the browser to a new URL. It is used for redirecting the browser to automatically perform any necessary URL encoding.

E.g<c:redirect url="http://xyz.com" />









 
 
 

Recent Posts

See All

Comentários


bottom of page