tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Petr Jiricka <petr.jiri...@netbeans.com>
Subject [PATCH]: loading JSPs compiled by external tools
Date Fri, 25 Feb 2000 17:39:03 GMT
Hello,

there was a discussion on this list some time ago about servlet reloading. I
would like to propose something similar for JSPs, i.e. reloading JSPs
compiled by external tools, by comparing timestamp of the JSP class with the
time the JSP was last loaded. Right now a page is reloaded only if the
source is newer than the class file, which does not hold if the page was
compiled by an external tool.

One of the conclusions of the servlet reloading discussion was that this
should really only be a development feature, which is not intended to be
used in a deployment environment. The same question could be asked for JSPs,
but in this case I am not sure about the answer. On the one hand it is true
that a JSP can potentially do things like store inner classes in session,
which makes reloading difficult or impossible to implement in accordance
with J2EE, on the other hand, JSPs ususally create only the presentation
side, and no business logic, so I can imagine that people might want to have
this feature switched on in a production environment (if load is low and
changes occur often).

In the current code I found no way of switching off automatic recompilation
for JSPs, which penalizes performance. With the feature I am suggesting the
penalty is even greater. I think there should be an option to turn off all
ways of JSP reloading.

The following patch thus will work well in a development environment, but I
am not sure about deployment environment.

Please let me know what you think.

Thanks
Petr

cvs diff: warning: unrecognized response `cvs: setgroups: Operation not
permitted' from cvs server
Index: JspServlet.java
===================================================================
RCS file:
/home/cvspublic/jakarta-tomcat/src/share/org/apache/jasper/runtime/JspServle
t.java,v
retrieving revision 1.17
diff -u -r1.17 JspServlet.java
--- JspServlet.java     2000/02/23 09:44:37     1.17
+++ JspServlet.java     2000/02/25 15:56:57
@@ -96,6 +96,7 @@
        HttpJspPage theServlet;
        String jspUri;
        boolean isErrorPage;
+        long lastLoaded = -1;

        JspServletWrapper(String jspUri, boolean isErrorPage) {
            this.jspUri = jspUri;
@@ -109,6 +110,7 @@
                        //loader.getJspServletClass(jspUri);
                // This is for the original protocol.
                destroy();
+                lastLoaded = System.currentTimeMillis();
                theServlet = (HttpJspPage) servletClass.newInstance();
            } catch (Exception ex) {
                throw new JasperException(ex);
@@ -143,7 +145,7 @@
                               Logger.INFORMATION);

            //if (loader.loadJSP(jspUri, cp, isErrorPage, req, res) ||
theServlet == null) {
-            if (loadJSP(jspUri, cp, isErrorPage, req, res)
+            if (loadJSP(jspUri, cp, isErrorPage, req, res, lastLoaded)
                     || theServlet == null) {
                 load();
             }
@@ -393,7 +395,8 @@
      *  @return true if JSP files is newer
      */
     public boolean loadJSP(String name, String classpath,
-       boolean isErrorPage, HttpServletRequest req, HttpServletResponse
res)
+       boolean isErrorPage, HttpServletRequest req, HttpServletResponse
res,
+        long lastLoaded)
        throws JasperException, FileNotFoundException
     {
        Class jspClass = (Class) loadedJSPs.get(name);
@@ -425,7 +428,15 @@
         }

        // Reload only if it's outdated
-       if((jspClass == null) || outDated) {
+        String className = ctxt.getServletClassName();
+        int end = className.lastIndexOf("_jsp_");
+        if (end != -1)
+            className = className.substring(0, end);
+        String outputDir = ctxt.getOptions().getScratchDir().toString();
+        String fileName = outputDir + File.separatorChar + className +
".class";
+        File jspClassFile = new File(fileName);
+
+       if((jspClass == null) || outDated || (lastLoaded <
jspClassFile.lastModified())) {
            try {
                jspClass = loader.loadClass(ctxt.getFullClassName());
                         //loadClass(ctxt.getFullClassName(), true);
@@ -434,9 +445,10 @@
                                          cex);
            }
            loadedJSPs.put(name, jspClass);
+            return !firstTime;
        }

-       return outDated;
+       return false;
     }

 }

Mime
View raw message