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 Tomcathttp://www.javaexperience.com/how-to-clear-jsp-cache-in-tomcat/ Tomcat
Latest posts by admin (see all)
- Detect Android API and Release version - August 23, 2014
- Draw Text on Image using Canvas Drawtext in Android - August 23, 2014
- Display Battery Info in android textview - August 23, 2014