JSP - JSTL Core <c:out> Tag

c:out is a tag used to display the result of an expression in the web browser, which works similarly to the way JSP's <%=...%> expression tag works. The only difference is that this tag helps avoid HTML characters so that you can avoid cross-site scripting.

<c:out> Tag Syntax

Syntax:
<c:out value="value/expression" default="<string>" escapeXml="<true or false>"/>

Attributes

AttributeRequiredDefaultDescription
valueYesNoneThis attribute is for evaluating expressions and displaying information.
defaultNoBodyThis attribute is used to display a default value if the resulting value of the <c:out> tag is null.
escapeXmlNotrueThis attribute checks whether the '&', '<', and '>' special characters in the resulting string should be converted to their respective HTML entities.

<c:out> Tag Examples

Here is an example where this <c:out> Tag is only displaying information to the web browser:

Example:
<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>

<!DOCTYPE html>
<html>
<head>
    <title>Example of out in core-JSTL</title>
</head>
<body>
    <c:out value = "${'<p>Example of c:out for Output</p>'}" default="Not Available" escapeXml="true"/>
</body>
</html>
Output:
<p>Example of c:out for Output</p>

Another example where this tag is used to display the result of an expression in the web browser:

Example:
The sum of two numbers is: <c:out value="${2+5}" />
Output:
The sum of two numbers is: 7

Scroll Back to Top