<c:out> Tag
The <c:out>
tag is used to display the result of an expression, similar to <%= %>
. The difference is that <c:out>
can directly access properties using the "." operator.
For example, to access customer.address.street
, you would write: <c:out value="customer.address.street">
.
The <c:out>
tag automatically ignores XML markup characters, so they are not treated as tags.
Syntax
<c:out value="<string>" default="<string>" escapeXml="<true|false>"/>
Attributes
The <c:out>
tag has the following attributes:
Attribute | Description | Required | Default Value |
---|---|---|---|
value | Content to be output | Yes | None |
default | Default output value | No | Content within the tag |
escapeXml | Whether to ignore special XML characters | No | true |
Example
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>c:out Tag Example</title>
</head>
<body>
<h1><c:out> Example</h1>
<c:out value="<Data to be displayed (without escaping characters)>" escapeXml="true" default="Default value"></c:out><br/>
<c:out value="<Data to be displayed (with escaping characters)>" escapeXml="false" default="Default value"></c:out><br/>
<c:out value="${null}" escapeXml="false">Default value when the expression result is null</c:out><br/>
</body>
</html>
The output will be:
<c:out> Example
<Data to be displayed (without escaping characters)>
<Data to be displayed (with escaping characters)>
Default value when the expression result is null