日期:2014-05-16  浏览次数:20411 次

关于不重启Tomcat,更新JSP生效,更新Class不生效的原因

今天看了一个帖子,帖子里中提到了“tomcat怎么保证jsp在修改后生效”,最后从评论中得到了答案。这里我自己也整理一下,留用。原文地址:http://tywo45.iteye.com/blog/1768354

JSP页面的最终归宿也是Class(JSP->Servlet->Class),为什么同样是Class,一般情况下(Tomcat server.xml中reloadable=false)修改了JSP后,会生效,而修改了Class文件后,不会生效,而要重启呢?

这是因为Tomcat对JSP进入了侦听,如果有修改,就会重新翻译成Servlet并最终编译成Class文件,替换掉原JSP页面对应的Class文件。Tomcat的内部机制是可以让这种Class文件立即生效的。而普通的Class文件修改后,不能立即生效。

在Tomcat的Conf/web.xml文件中,可以对Tomcat的这种对JSP修改的机制进行修改。

  <!--   modificationTestInterval                                           -->
  <!--                       Causes a JSP (and its dependent files) to not  -->
  <!--                       be checked for modification during the         -->
  <!--                       specified time interval (in seconds) from the  -->
  <!--                       last time the JSP was checked for              -->
  <!--                       modification. A value of 0 will cause the JSP  -->
  <!--                       to be checked on every access.                 -->
  <!--                       Used in development mode only. [4]             -->

?

在“development”(开发模式)下,可以使用modificationTestInterval来设置Tomcat检查JSP更新的时间间隔,单位为秒,默认4秒

  <!--   checkInterval       If development is false and checkInterval is   -->
  <!--                       greater than zero, background compilations are -->
  <!--                       enabled. checkInterval is the time in seconds  -->
  <!--                       between checks to see if a JSP page (and its   -->
  <!--                       dependent files) needs to  be recompiled. [0]  -->

?

在非“development”模式下,使用checkInterval来设置Tomcat检查JSP更新的时间间隔,单位为秒,默认为不检查。

?

对于上面提到的“development”模式,也是在web.xml文件中配置的,如下

  <!--   development         Is Jasper used in development mode? If true,   -->
  <!--                       the frequency at which JSPs are checked for    -->
  <!--                       modification may be specified via the          -->
  <!--                       modificationTestInterval parameter. [true]     -->

默认情况下Tomcat使用“development”?模式。

?