How do use c:forEach JSTL tag?

Share:

The c:forEach tag in the core JSTL tag library is a useful tag when we want to iterate over a collection of data such as array. It is commonly use to render a tabular data in our web pages in form of HTML table.

In the example below we display a weather data that we stored as two dimensional array of string. After declaring and initializing the data with some value we put it into the request scope. Later on the c:forEach tag can use the data, iterates it row by row to form an HTML table. Our weather data consist of the date, condition and the high and low temperature.

Our JSP page above creates the following output:

5-Days Weather for Denpasar, Indonesia

DATECONDITIONTEMP. HIGHTEMP. LOW
Nov 6Sunny32℃26℃
Nov 7Sunny32℃26℃
Nov 8Sunny32℃26℃
Nov 9Partly Cloudy32℃26℃
Nov 10Isolated T-Storms32℃26℃
Share: