修改jsp页面为什么不用重启Tomcat

修改JSP页面为什么不用重启Tomcat

JSP->servlet->.clsss

JSP最终要转换为class文件,为什么tomcat在修改java代码的必须先重启tomcat,反而JSP不用。?

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

 

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

 

需要配置tomcat 的 sever.xml 文件:

<Context  docBase="test"  path="/test"   reloadable="false"  source="org.eclipse.jst.jee.server:test"/></Host>

当 reloadable="true" 时候,修改页面js和css文件时, 有时不需要重启tomcat,有时需要重启tomcat
当 reloadable="false" 时候,修改页面js和css文件时,始终不用重启tomcat,但是修改后台代码时需要重启tomcat

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” 模式。

 

  • 12
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值