The reason why JSPs don't call getLastModified() is that the call is done in the service() method in the Servlet base class. This method is overriden in most JSP implementations (at least, in all I know), so the functionality is lost.
 
Why don't you create your own JSP base? You could use HttpJspBase.java from Tomcat source as a template.
 
Once you have your base class in the CLASSPATH (general, not web-app), you only add "extends" attribute to the page directive in your pages and you get the desired behaviour.
 
The idea can be used for any functionality you would need to be able in all your pages :-)
 
Here you have an example of such a servlet. It adds a validate() method that can be implemented in JSPs that inherit from this class. I created it to separate form validation code in my JSPs, but the same can be used to force a call to getLastModified():
 
 
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
 
public abstract class MyJspBase extends HttpServlet implements HttpJspPage {
 
  private ClassLoader cl;
 
  protected PageContext pageContext;
 
  protected MyJspBase() {}
 
  public final void init(ServletConfig config) throws ServletException {
    super.init(config);
    jspInit();
  }
 
  public String getServletInfo() {
    return "My JSP Base Servlet";
  }
 
  public final void destroy() {
    jspDestroy();
  }
 
  public final void setClassLoader(ClassLoader cl) {
    this.cl = cl;
  }
 
  protected ClassLoader getClassLoader() {
    if (cl == null) return this.getClass().getClassLoader();
    return cl;
  }
 
  /**
   * Entry point into service.
   */

  public final void service(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    // Check validation before serving the page
    if (doValidate(request, response)) _jspService(request, response);
  }
 
  private boolean doValidate(HttpServletRequest request, HttpServletResponse response) throws IOException {
    try {
      return validate(request, response);
    }
    catch (Exception e) {
      try {
        pageContext.handlePageException(e);
      }
      catch (Exception ee) {
        response.sendError(response.SC_INTERNAL_SERVER_ERROR, ee.getMessage());
      }
      return false;
    }
  }
 
  public boolean validate(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    return true;
  }
 
  public void jspInit() {}
  public void jspDestroy() {}
  public abstract void _jspService(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException;
}
 
 
Best Regards :-)

Reply via email to