<%@ page import="java.io.File" errorPage="err.jsp" %> <%@ taglib uri="gnat" prefix="gnat" %> <%-- Use the Servlet 2.2+ temporary working directory to demo some file stuff. Makes it easier because the user doesn't have to configure anything and I don't have to worry about file system and user permissions for the demo. See section 3.7 of Servlet 2.3 spec for description of this attribute. --%> <%! File tempdir = null; %> <% tempdir = (File)application.getAttribute("javax.servlet.context.tempdir"); %> Gnat JSP Taglib

Gnat Taglib: touch

<%-- Until JRun and Jasper escape String literals nested in custom tag attributes properly, it's best to declare them as variables and then use their variable names rather than the literal strings. The multitude of double quotations seems to confuse JRun (3.0, SP1) and Jasper (3.3.dev), though JRun can deal with them if the quotes around the whole attribute are removed. --%> <%-- Name of file to create in demo --%> <% final String foo = "/touched-file.txt"; %> <% final String foo2 = "/second-touched-file.txt"; %>

Changes the modification time of a file and possibly creates it at the same time. The touch examples in this page are created in <%= tempdir %>

<gnat:touch file="/file/to/touch" millis="modtime in millis" datetime="modtime date format"/>

example 1 - millis can be assigned dynamically, using an expression:

<gnat:touch file="<%= tempdir+foo %>" millis="<%= new java.util.Date().getTime() %>" />

example 2 - Or millis can be assigned statically, using milliseconds since midnight Jan 1 1970...

The example below sets the last modified time as 12/24/2000 21:15pm

<gnat:touch file="<%= tempdir+foo %>" millis="977710526363" />

example 3 - Or millis can be assigned statically, using a formatted date. The datetime variable must be set in format: MM/DD/YYYY HH:MM AM or PM.

<gnat:touch file="<%= tempdir+foo2 %>" datetime="06/28/1983 2:02 pm" />