Show Last Modified Date in JSP
I would like to show the Last Modified Date of a JSP that uses Tomcat
container.
I can do it this way using Java in JSP:
<%@ page import="java.io.*, java.text.*, java.util.*" %> Last
Modified:
<%
String jspPath =
getServletContext().getRealPath(request.getServletPath());
File jspFile = new File(jspPath);
Date lastModified = new Date(jspFile.lastModified());
SimpleDateFormat fmt = new SimpleDateFormat("EEEE, MMMM dd, yyyy, h:mm
a(zz)");
out.println(lastModified);
%>
But I would rather take the Java out of the JSP and use Java Bean to
show the last modified date.
My below attempt in the Bean class gives me errors with request object
and I also need help in getting it to work. Please advise.
package data;
import java.io.*;
import java.text.*;
import java.util.*;
public class DateBean
{
private String mydate = "";
public DateBean()
{
}
public String fetchDate(String mydate)
{
String jspPath =
getServletContext().getRealPath(request.getServletPath());
File jspFile = new File(jspPath);
Date lastModified = new Date(jspFile.lastModified());
SimpleDateFormat fmt = new SimpleDateFormat("EEEE, MMMM dd, yyyy,
h:mm a(zz)");
return fmt.format(lastModified);
}
public String getMydate()
{
return mydate;
}
public void setMydate(String mydate)
{
fetchDate(mydate);
this.mydate = mydate;
}
}