Why can we see the changes made to the jsp when the page is refreshed? why not for a servlet?

Why can we see the changes made to the jsp when the page is refreshed? why should we restart the server in case of any changes made to the servlet? what is the difference between both?

+3


source to share


3 answers


Servlets are precompiled class files, but jsp will only compile at runtime. And we have a jasper listener for jsp, it will notify the server when we change jsp, then the server will replace the old class file with the new one. This is why jsp changes are reflected immediately.



+2


source


Servlets are compiled classes that we load somewhere in WEB-INF, but copy them to our base workstation to run them. Until they are changed in the THAT location, the changes will not be reflected, and this will only happen when the server is restarted.



In the case of a jsp page, When Tomcat is prompted to execute a JSP, it compares the modified date of the JSP file with the modification time of the compiled class corresponding to that JSP, and if it is more recent, it is recompiled on the fly before executing it.

+1


source


The other answers are correct, however you asked, "Why do we have to restart the server?" You do not. You just need a server to use the updated file, not fetch it from the cache. There are several ways to do this. For Tomcat 8.0.21 it seems to be true that saving changes to web.xml causes the server to use files rather than cache.

The fastest way I've found to do this is add space, save, remove space, save again. Also, I've done this in a significant area, like in url tags.

0


source







All Articles