为什么在更改jsp时不需要重启tomcat
我一直在使用JSP,Servlet
。 我知道每当我们在Servlet
更改任何内容时,我们都需要重新启动Tomcat Server才能获得更改。 在JSP更改的情况下,tomcat不需要重新启动。
据我所知, JSP
页面只有在编译时才会转换为Servlet
。 所以,毕竟它是一个Servlet
。所以,如果没有Tomcat
重启,它是如何工作的。
我知道JSP页面在服务器重启后第一次访问时编译的情况。
因为默认情况下tomcat是在开发模式下启动的,这意味着在检测到更改时会重新编译JSP派生的servlet。 这是一个很好的问题,JVM如何加载新类 – 可能是tomcat类加载器配置为这样做。
一些相关的说明:
- 您可以关闭生产的开发选项
- 你也可以重新加载servlet – 你必须在调试模式下使用JVM启动tomcat。
因为当要求Tomcat执行JSP时,将JSP文件的修改日期与对应于此JSP的编译类的修改时间进行比较,如果是更新的,则在执行之前重新编译。
这是BTW应该在生产中关闭的选项,因为执行此检查需要时间。
有关详细信息,请参见http://tomcat.apache.org/tomcat-7.0-doc/jasper-howto.html 。
不仅JSP的某些容器还支持重新加载servlet类(如果它被修改)。
决定何时加载servlet是由容器决定的。 A servlet can be loaded at runtime on demand
。 而来到JSP, JSP translated to servlet can also be loaded at runtime
。
来到你的问题,
为什么Tomcat不需要重启?
这是因为Tomcat is capable of adding/modifying classpath to Web Application classloader at runtime
。 Tomcat将拥有custom Classloader implementation which allows them to add the classpaths at runtime
。
自定义类加载器如何工作?
实现此function的一种方法是在修改a new classloader is created for the Servlet/JSP with Application classloader as parent classloader . And the new classloader will load the modified class again
a new classloader is created for the Servlet/JSP with Application classloader as parent classloader . And the new classloader will load the modified class again
。