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.


<webinf:copyrightyear>Example</webinf:copyrightyear>

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" />