JSP Copyright tag file example

This is a simple example in .tag files, the concepts can apply to many other uses.

I’ve chosen the following common usage example:

Websites often need to contain copyright date and information in their footer.

Add this to your existing JSP page (or JSPF fragment):

<%@ taglib prefix="webinf" tagdir="/WEB-INF/tags" %>
<webinf:copyrightyear />

Create the .tag file – /WEB-INF/tags/copyrightyear.tag

<%@ tag language="java" isELIgnored="true" trimDirectiveWhitespaces="true" description="dynamically calculates year" %>
&#169;<jsp:expression>java.util.Calendar.getInstance().get(java.util.Calendar.YEAR)</jsp:expression>&#160;<jsp:doBody />

NOTE: I’ve used the <jsp:doBody /> inside the tag file in this example, as such you can also use the following format on your page(s) to use the content between the open and close.


NOTE: if your server supports it, you can also use XML formatted tag file with:

<jsp:directive.tag language="java" isELIgnored="true" trimDirectiveWhitespaces="true" description="dynamically calculates year" />

Happy Leap Day

Ah,  we have an extra day this year.   Each time it reminds me of just how many people assume that these happen every four years, completely disregarding the rule or reason for these.

  1. Every year divisible by 4 is a leap year,
  2. of those years, if it is divisible by 100, it is NOT a leap year, unless
  3. the year is divisible by 400, in which case it IS a leap year.

The year 2000 was a leap year for this reason, as you can see… unless you apply all of the rules, your programatic date calculations may be incorrect in these cases.

While on the topic, there’s also the little known concept as a ‘leap second’, unless you are involved in communications or scientific applications you are probably not aware of this.   Back when I was involved in submarine communications, we used to have to update our atomic (cesium beam) clocks to accomodate this irregularly planned change.


By the way, Happy Birthday to you ‘young ones’ born today!