0

So i am developing a web app. So there is java script files and java Servlet class files. I am running my app in tomcat server. So when i make any change in the JSP file if i reload the browser then the changes are getting reflected instantly. But if i make any change in the servlet code why i need to start the server again to see my changes gets reflected? Can someone give a clear note on why server restart is required in the second case? Did the recompiled java class file requires the server to be restarted?

giri dharan
  • 157
  • 4
  • 12

3 Answers3

1

due to J2EE container implementaion, in tomcat,

JSP -- use a stand-alone ClassLoader;

Normal Servelet and other class -- AppClassloader

when a jsp changed, the new compiled Servlet(different from user defined Servlet) class will be loaded by a new stand-alone ClassLoader.

Kangxi Hou
  • 26
  • 1
0

Servlet and JSP are all the servlet, both of them are the class files during their runtime. But their deployment way are different.

The servlet is first compiled deployment, after you have modified, Eclipse compile, and deploy. Class files into the servlet container. If the web server is started, before the class has been the servlet container loading, and may be modified class files will not be executed in the servlet container.

Compile and JSP is a web server. Tomcat can be set to monitor changes in the JSP file, after changes, recompile, executed.

Jay Gong
  • 23,163
  • 2
  • 27
  • 32
-1

Yes, Indeed, when modifications are made to .java files, they need to be recompiled and converted to .class files which are stored in the target folder or the webapps folder of your tomcat server. This change necessitates a restart. Although, eclipse is configured to restart your tomcat automatically triggering a context reload after some time.

Joey Pinto
  • 1,735
  • 1
  • 18
  • 34
  • JSP file if changed getting swapped with the existing file. But in the case of java file why it is not happenning? – giri dharan Jul 11 '17 at 05:51
  • JSP files undergo the Java interpreter not compiler. They are interpreted like javascript, when you call them. – Joey Pinto Jul 11 '17 at 05:53
  • @JoeyPinto Really, try having a look under the `work` directory of tomcat. You will see that jsp files get converted into java file and then compiled to class files – Scary Wombat Jul 11 '17 at 06:03