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:useBeanid="currentDate"class="java.util.Date"/> <fmt:formatDatevar="year"value="${currentDate}"pattern="yyyy"/> <p>Β© 2010-${year} ABCD Inc. All rights reserved</p>
For Java 8 or above we can print current year with single line of code
<%= LocalDate.now().getYear() %>