The book in the link provided by sourabh girdhar is very old and outdated.
This link covers the custom class loaders used in Apache
Tomcat (one of the most popular servlet containers today).
http://tomcat.apache.org/tomcat-7.0-doc/class-loader-howto.html
In it, you'll see that there is a separate link for each application within the server but nothing is mentioned about having a separate loader for each servlet.
A more fun way to learn about class class loaders is to put some print statements into a web app and start hitting it.
The following line will print the classloader information for the current class to the logs (or console depending on how your container is configured)
I just did this in a small
test app. I put the statement in two servlets and then ran them.
From the output, you can see that both servlets are using the same classloader.
This makes sense because, in Tomcat, you can not reload a single servlet. You have to reload the entire app if you change a servlet.
With modern
JEE programming, you probably wouldn't want a container to reload a single servlet as many apps these days are built with frameworks that only have one servlet that acts as a controller. Often this controller holds references to other
Java objects within the app. Reloading just the controller without the rest of the app could cause very hard to trace bugs.
An interesting note:
The Jasper
JSP engine used by Tomcat does create separate classloaders for each JSP.
This makes sense because JSPs need to be able to be reloaded whenever a change is made to them.
To print the classloader information in a JSP
The results after pasting that line into two different JSPs and hitting them:
Also, if you hit a JSP, and then update the code in it and hit it again, you'll see that a new class loader gets created: