trainingtrains Logo

91-9990449935

 0120-4256464

JSTL (JSP Standard Tag Library)

The JSP Standard Tag Library (JSTL) represents a set of tags to simplify the JSP development.

Advantage of JSTL

  1. Fast Developement JSTL provides many tags that simplifies the JSP.
  2. Code Reusability We can use the JSTL tags in various pages.
  3. No need to use scriptlet tag It avoids the use of scriptlet tag.

There JSTL mainly provides 5 types of tags:

Tag NameDescription
core tags The JSTL core tag provide variable support, URL management, flow control etc. The url for the core tag is http://java.sun.com/jsp/jstl/core . The prefix of core tag is c.
sql tags The JSTL sql tags provide SQL support. The url for the sql tags is http://java.sun.com/jsp/jstl/sql and prefix is sql.
xml tags The xml sql tags provide flow control, transformation etc. The url for the xml tags is http://java.sun.com/jsp/jstl/xml and prefix is x.
internationalization tags The internationalization tags provide support for message formatting, number and date formatting etc. The url for the internationalization tags is http://java.sun.com/jsp/jstl/fmt and prefix is fmt.
functions tags The functions tags provide support for string manipulation and string length. The url for the functions tags is http://java.sun.com/jsp/jstl/functions and prefix is fn.

For creating JSTL application, you need to load jstl.jar file.


download jstl1.2.jar file

JSTL Core Tags

The JSTL core tags mainly provides 4 types of tags:

  • miscellaneous tags: catch and out.
  • url management tags: import, redirect and url.
  • variable support tags: remove and set.
  • flow control tags: forEach, forTokens, if and choose.

Syntax for defining core tags


c:catch

It is an alternative apporach of global exception handling of JSP. It handles the exception and doesn't propagate the exception to error page. The exception object thrown at runtime is stored in a variable named var.

Example of c:catch

Let's see the simple example of c:catch.


c:out

It is just like JSP expression tag but it is used for exression. It renders data to the page.

Example of c:out

Let's see the simple example of c:out.

index.jsp
process.jsp

c:import

It is just like jsp include but it can include the content of any resource either within server or outside the server.

Example of c:import

Let's see the simple example of c:import to display the content of other site.

index.jsp

Example of c:import to display the source code

Let's see the simple example of c:import to display the source code of other site.

index.jsp

c:forEach

It repeats the nested body content for fixed number of times or over collection.

Example of c:forEach

Let's see the simple example of c:forEach.


c:if

It tests the condition.

Example of c:if

Let's see the simple example of c:if.


c:redirect

It redirects the request to the given url.

Next TopicCustom Tags