On Jul 23, 9:05 am, "tes...@hotmail.com" <tes...@hotmail.com> wrote:
> I would like to show the Last Modified Date of a JSP that uses Tomcat
> container.
[quoted text clipped - 52 lines]
>
> }
Since you call Servlet methods and access request object, your
DateBean class should be an HttpServlet class. A stand alone custom
Java class can't access them.If you insist on using a plain Java
class, you should get the JSP file path using more generic means, like
a String literal path string.
teser3@hotmail.com - 24 Jul 2007 02:30 GMT
Thanks, I ended up putting this in a Bean class and hard coding file
name in the Bean class and it works but now I would like to have the
file name passed as a condtion in the JSP Java Bean call.
Here is how it works with hardcoding the file name in the bean class
and calling it in my JSP where it outputs the last modified date and
works great:
Last modified Date:
<jsp:useBean id="datebeann" scope="page" class="data.DateBean" />
<jsp:setProperty name="datebeann" property="*" />
<jsp:getProperty name="datebeann" property="mydate" />
Java Bean class:
package data;
import java.io.*;
import java.text.*;
import java.util.*;
public class DateBean
{
private String mydate = "";
public DateBean()
{
this.mydate = fetchDate();
}
public String fetchDate()
{
String jspPath = "C:\\tomcathome\\mydate2.jsp";
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)
{
this.mydate = mydate;
}
}
The above works but now how can I put the filename in the setProperty
so I can have a variable in the JSP. I tried all the below and it
just prints out a literal value: C:\\tomcathome\\anotherFile.jsp.
Please advise.
Last modified Date:
<jsp:useBean id="datebeann" scope="page" class="data.DateBean" />
<jsp:setProperty name="datebeann" property="mydate" value="C:\
\tomcathome\\anotherFile.jsp" />
<jsp:getProperty name="datebeann" property="mydate" />
Attempt in Java Bean:
private String mydate = "";
private String filename = "";
public DateBean()
{
this.mydate = fetchDate(filename);
}
public String fetchDate(String jspPath)
{
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);
}