March 2, 2011

JSTL 1.1 - <c:out> example

test.jsp


Example 1:

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:out value="<h1>Hello</h1>" escapeXml="false" />

prints:

Hello


Example 2:

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:out value="<h1>Hello</h1>" escapeXml="true" />

prints:

<h1>Hello</h1>

Example 3:

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<% session.setAttribute("cart",null); %>
<c:out value="${sessionScope.cart}" default="Shopping Cart is Empty" />

prints:

Shopping Cart is Empty  (when ${sessionScope.cart} evaluates to a null value)


No comments:

Post a Comment