关于不重启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修改的机制进行修改。

Java代码   收藏代码
  1. <!--   modificationTestInterval                                           -->  
  2. <!--                       Causes a JSP (and its dependent files) to not  -->  
  3. <!--                       be checked for modification during the         -->  
  4. <!--                       specified time interval (in seconds) from the  -->  
  5. <!--                       last time the JSP was checked for              -->  
  6. <!--                       modification. A value of 0 will cause the JSP  -->  
  7. <!--                       to be checked on every access.                 -->  
  8. <!--                       Used in development mode only. [4]             -->  

 

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

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

 

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

 

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

Java代码   收藏代码
  1. <!--   development         Is Jasper used in development mode? If true,   -->  
  2. <!--                       the frequency at which JSPs are checked for    -->  
  3. <!--                       modification may be specified via the          -->  
  4. <!--                       modificationTestInterval parameter. [true]     -->  

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

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值