Display year in jsp using jstl

As a programming standard, we don’t use java scriptlets in our JSP files. The best practice is to use JSTLs in JSP files to load the dynamic contents.

Displaying current year in JSP is one of the common requirement, at least for copyright messages.

Displaying current year in JSP can be achieved by using the following JSTL code.

<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<jsp:useBean id="currentDate" class="java.util.Date" />
<fmt:formatDate var="year" value="${currentDate}" pattern="yyyy" />
<p>© 2010-${year} ABCD Inc. All rights reserved</p>


Leave a Reply

Your email address will not be published. Required fields are marked *