Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are my JSP changes are not reflected without restarting Tomcat?

I am editing JSP files which are residing directly inside tomcat/webapps/myapp/WEB-INF, but to see the changes, I have to restart the server. As far as I know, JSP changes don't require you to restart the server. The only configuration I found which is related to automatic reloading is reloadable = "true"

Set to true if you want Catalina to monitor classes in /WEB-INF/classes/ and /WEB-INF/lib for changes, and automatically reload the web application if a change is detected.

I used this attribute in the context.xml, but still the problem persists. What could be the other possible reason of not detecting changes in JSP files without restarting?

@Bozho: This is the excerpt from web.xml. Do I need to change something?

 <servlet>         <servlet-name>jsp</servlet-name>         <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>         <init-param>             <param-name>fork</param-name>             <param-value>false</param-value>         </init-param>         <init-param>             <param-name>xpoweredBy</param-name>             <param-value>false</param-value>         </init-param>         <load-on-startup>3</load-on-startup>     </servlet> 
like image 280
Rakesh Juyal Avatar asked Jan 05 '10 07:01

Rakesh Juyal


People also ask

Why Tomcat does not require restart when JSP is changed?

It is because Tomcat is capable of adding/modifying classpath to Web Application classloader at runtime . Tomcat will be having their custom Classloader implementation which allows them to add the classpaths at runtime .

Does JSP change need server restart?

For example, you can modify JSP source and the changes will reload automatically on the server. For other resources, such as Java classes that are running on Tomcat, you must restart the server to ensure that the changes are recognized by the server.

How do you resolve if a change made in JSP file is not reflected?

Resolving The Problem The best thing to do is identify the compiled java and the class file that corresponds to the jsp in the work folder and delete it. This will force the jsp to be recompiled and the changes will show up. 2. Another option is to "touch" the JSP to reset the updated date.

How to refresh jsp page after update?

Answer: When we need to refresh the web page automatically after some time, we use JSP setIntHeader() method. This method sends back header "Refresh" to the browser along with an integer value which indicates time interval in seconds. It is used when we need to display live game score, share market status etc.


1 Answers

In the tomcat docs, see the development setting. It must be set to true in order to have jsps reloaded.

development - Is Jasper used in development mode? If true, the frequency at which JSPs are checked for modification may be specified via the modificationTestInterval parameter.true or false, default true.

This is in your CATALINA_HOME/conf/web.xml

Additionally, if you need to refresh a jsp in a production environment without restart, you can go to CATALINA_HOME/work/Catalina/localhost/contentName/org/apache/jsp and delete the your_jsp.java and your_jsp.class files. They will be recreated the next time they are accessed.

Edit: after providing your configuration, and comment about not refreshing the content, I have another though: clear your browser cache, or open the page from another browser.

like image 171
Bozho Avatar answered Sep 22 '22 12:09

Bozho