Java – why tomcat does not require restart when jsp is changed

javajspservletstomcat

I have been using JSP,Servlet for quite sometime. I know that whenever we change anything in Servlet we need to restart Tomcat Server to get the changes. Where as in case of JSP change, tomcat does not require restart.

As per my knowledge JSP page gets converted into Servlet only when compiled. So, after all its a Servlet.So, How does it works without Tomcat restart.

I have knowledge of cases when a JSP page gets compiled like on first time access after server restart etc.

Best Answer

Because when Tomcat is asked to execute a JSP, is compares the modification date of the JSP file with the modification time of the compiled class corresponding to this JSP, and if more recent, it recompiles on the fly before executing it.

This is BTW an option that should be turned off in production, because it takes time to perform this check.

See http://tomcat.apache.org/tomcat-7.0-doc/jasper-howto.html for details.

Related Topic