As soon as you deploy web application in tomcat, the jsp in the web application get compiled and then the JSP life-cycle is executed. The translated .java and compiled class files for JSP are renamed randomly and placed in the work folder of tomcat as shown below:

Next time the JSP is requested, code from this .class file is executed and served to the users. Thus it is not recompiled every time. However if during development, you make a change in some JSP in your application, the JSP is recompiled into servlet and the JSP life-cycle starts again. This approach of hot deployment can be used in production environment too where you need to patch code in one JSP file only.

This placement of servlet .class file for a JSP file in the work folder of tomcat is known as JSP cache. Tomcat looks at the timestamp of JSP files periodically and re-compiles if a change in timestamp is detected. However in some cases this doesn’t happen and JSP cache is not updated. Here are a few things you may try to clear JSP cache in Tomcat:

  • 1) Stop the server. 2) Remove WAR file from webapps folder. 2) Remove application directory in the work folder 3) Redeploy the application. 4) Start the server

    Caution: This will also remove the persisted sessions kept in the work folder for the application.

  • Check if changes have been done in one of the included JSP, if so then make a dummy change (adding white space) in the parent JSP. This will update the time-stamp of parent JSP and hence recompile the parent and include fresh code from child JSPs. You would want to do this when using include directive which performs inclusion of one JSP to another during translation phase only.
  • Clear the web browser cache. This can be done by going to the options of browser or pressing Ctrl+F5 in the window/tab where the application JSP has been opened.
  • If you want to avoid JSP caching altogether on the browsers then add the following meta tags to header jsp:
    <META HTTP-EQUIV="Expires" CONTENT="0">
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-store">
    

    Caution: You won’t get performance benefit of serving pages from cache. It is recommended to allow page caching in application running on internet to decrease user wait time.

Please note that How to clear JSP cache in Tomcat is also an important Tomcat interview question.

How to clear JSP cache in Tomcat admin Tomcat
As soon as you deploy web application in tomcat, the jsp in the web application get compiled and then the JSP life-cycle is executed. The translated .java and compiled class files for JSP are renamed randomly and placed in the work folder of tomcat as shown below: Next time the...
As soon as you <a href="http://www.javaexperience.com/deploy-servlet-on-tomcat/">deploy web application in tomcat</a>, the jsp in the web application get compiled and then the JSP life-cycle is executed. The translated .java and compiled class files for JSP are renamed randomly and placed in the work folder of tomcat as shown below: <img src="http://www.javaexperience.com/wp-content/uploads/2012/12/tomcat cache folder.png" width="597px" height="210px"/> Next time the JSP is requested, code from this .class file is executed and served to the users. Thus it is not recompiled every time. However if during development, you make a change in some JSP in your application, the JSP is recompiled into servlet and the <a href="http://www.javaexperience.com/understanding-jsp-lifecycle/">JSP life-cycle</a> starts again. This approach of hot deployment can be used in production environment too where you need to patch code in one JSP file only. This placement of servlet .class file for a JSP file in the <strong>work folder of tomcat</strong> is known as JSP cache. Tomcat looks at the timestamp of JSP files periodically and re-compiles if a change in timestamp is detected. However in some cases this doesn't happen and JSP cache is not updated. Here are a few things you may try to clear JSP cache in Tomcat: <ul> <li>1) Stop the server. 2) Remove WAR file from webapps folder. 2) Remove application directory in the work folder 3) Redeploy the application. 4) Start the server <blockquote>Caution: This will also remove the persisted sessions kept in the work folder for the application.</blockquote> </li> <li>Check if changes have been done in one of the included JSP, if so then make a dummy change (adding white space) in the parent JSP. This will update the time-stamp of parent JSP and hence recompile the parent and include fresh code from child JSPs. You would want to do this when using include directive which performs inclusion of one JSP to another during translation phase only.</li> <li>Clear the web browser cache. This can be done by going to the options of browser or pressing Ctrl+F5 in the window/tab where the application JSP has been opened.</li> <li>If you want to avoid JSP caching altogether on the browsers then add the following meta tags to header jsp: 1 <blockquote>Caution: You won't get performance benefit of serving pages from cache. It is recommended to allow page caching in application running on internet to decrease user wait time.</blockquote> </li> </ul> Please note that <strong>How to clear JSP cache in Tomcat</strong> is also an important <a href="http://www.javaexperience.com/tomcat-server-interview-questions-and-answers/">Tomcat interview question</a>.