tags:

views:

889

answers:

2

I am referring to the following parameter of Tomcat's web.xml file:

<servlet>
    <servlet-name>jsp</servlet-name>
    <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
         . . . 
    <init-param>
        <param-name>development</param-name>
        <param-value>true</param-value>
    </init-param>
         . . . 
</servlet>

Is there any way for a web application to programmatically toggle this value -- at least for itself if not for all web applications -- so this can be temporarily changed on a running web server without having to stop and restart Tomcat?

Failing this, is there a way to force a single JSP to recompile without having to wait the few non-deterministic minutes it may take otherwise? I know that if you change a JSP, it will eventually (within a few minutes) be compiled, but I'm looking for a way to say, "On the next access, recompile it."

NOTE: Solutions which require restarting the web application or which will result in a web app restart or a container restart won't help me. I already know how to do this (by hand) for times when I can restart Tomcat. What I am trying to do is to temporarily switch the "development" value from false to true on a Tomcat instance in production, where I cannot interrupt current sessions.

A: 

As far as I know, if you modify a web app's web.xml, the container (tomcat) is restarted automatically. Also the parameter values in web.xml can only be read programatically.

If you want to your JSP recompiled right away, just request that JSP's URL, or change the default ModificationTestInterval for JSP to 0 seconds:

        <init-param>
            <param-name>modificationTestInterval</param-name>
            <param-value>0</param-value>
        </init-param>
        <init-param>
            <param-name>development</param-name>
            <param-value>true</param-value>
        </init-param>

. Hope this helps.

Igor Zelaya
I can't restart the web application. Doing so will destroy state and interrupt active sessions. Changing the modificationTestInterval to 0 puts me into the same boat I am in right now ... how do I do that programmatically?
Eddie
I just updated my question to make my goals more clear.
Eddie
@Eddie. If you modify web.xml programatically or by hand it will cause a container restart.
Igor Zelaya
@Eddie. You can modify JSP though mannually without causing a container restart.
Igor Zelaya
@Igor Zelaya: Is it possible to do the EQUIVALENT of modifying Tomcat web.xml programmatically in a way to change the "development" parameter but without causing a container restart?
Eddie
+1  A: 

The default behaviour of JspServlet is to check the source JSP every time it is accessed, and if it has changed, then recompile. This setting works fine in 99% of situations, including development and production. Under very high load, then disabling this may speed things up, but I've yet to see that as necessary.

If you're seeing behaviour where the JSP is eventually recompiled, then you must have configured Tomcat to behave that way. Have you enabled the background recompilation flag, as detailed here? This setting might implicitly disable automatic on-access recompilation.

skaffman