Outputting with c:out Action

In this tutorial, you will learn how to use action c:out to output variables and expressions on a web page.

<c:out> action is used to evaluate a variable or expression and output it. <c:out> is similar to the expression <%=  expression%>. The usage of <c:out> action is as follows:

There are two attributes:

  1. Value:  You can put a variable or expression here
  2. default value: if the variable or expression is evaluated as null, the default value will be used for output.

The other form of the <c:out> action is as follows:

If the expression is evaluated as null, the body between the opening and closing tag will be used for output.

Let’s take a look at an example of using <c:out> action:

First we use <c:out> to output the variable x. Because variable x does not exist so the output is a string specified in the default value.

Second we use <c:set> action to declare a variable called i. You will learn more about the c:set action is the next tutorial. then we output the variable i, at this time we get the value of i displaying which is 10.

Last we use an expression which is (i + 10) so we get 20 displaying.

Here is the screenshot of the output:

JSTL c:out

  • Was this tutorial helpful ?
  • YesNo