aspose file tools*
The moose likes JSP and the fly likes Difference between JSP and Servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Difference between JSP and Servlets" Watch "Difference between JSP and Servlets" New topic
Author

Difference between JSP and Servlets

Ashish Vijay Joshi
Greenhorn

Joined: Nov 27, 2006
Posts: 10
Hello,
I want to know why we need not restart apache/tomcat server if we make a change in jsp file. Just refreshing a browser will reflect my changes. On the other hand if i make a change in servlet(java file) i need to restart tomcat/apache to reflect those changes.

Regards
Ashish
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Containers have separate class loader for JSPs and are designed to watch the dates of the files to reload them when they change.
This makes editing JSPs as easy as working with scripting languages like PHP, ASP, Perl, etc....


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ashish Vijay Joshi
Greenhorn

Joined: Nov 27, 2006
Posts: 10
Thanks for reply.
Does it mean that separate class loaders are used for servlets and jsps.
Container might be running inside one VM having default embedded class loader which is used to load servlet class files,but in case of JSP custom class loaders are used is it what you mean. Moreover it chooses files to recompile
based on timestamps.
PS: If you can throw some light on what it means by precompilation of jsps.

Regards
Ashish
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Not separate JVMs.
They all run under the same JVM but there are custom classloaders to make JSPs behave more like scripts.

If you can throw some light on what it means by precompilation of jsps.


As the name implies, it's possible to compile all the of the JSPs in an application ahead of time. There are ups and downs to doing this.
Doing so means that each page is already compiled before the first user hits it so the user doesn't experience the slight delay that it takes to compile the JSP to servlet code, compile the servlet to byte code, and load the servlet. When deployed this way, some containers allow you to shut off the checking mechanism (the one that checks the date stamp of each JSP before serving it up) which also speeds things up. From a security standpoint, an app with pre-compiled JSPs doesn't require a compiler. If there is no compiler on the production server, then it is harder for a hacker to get their own code running on that box.

The down side is that you loose the script like convenience of being able to upgrade an app on the fly by editing or replacing a simple JSP file (which is a text file).
[ June 04, 2008: Message edited by: Ben Souther ]
Ashish Vijay Joshi
Greenhorn

Joined: Nov 27, 2006
Posts: 10
Got it!!! Thanks
Ashish
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference between JSP and Servlets