Servlets run inside of a "container". I tend to use
Tomcat, which can be run in a stand-alone mode or part of a larger web server such as Apache. When you start Tomcat it defines a classpath and starts Java--it's own JVM. Since lots of servlets can run inside that JVM they can share resouces, such as connections from a pool, beans, etc.
I believe that when there are multiple applets running in a web page there is still only one JVM, which is why applets can "talk" to each other.
Note that in a distributed model where there are muliple servers handling incoming requests this requires special programming. You either lock the user [each session] into a single server, or you have to synchronize the session state between the servers.
This is a simplistic explanation and perhaps others can add details. But as I mentioned previously, APIs such as sockets, RMI and HTTP allow data--and in some cases
Java objects themselves--to be passed between machines and JVMs.
So you could use sockets or RMI to create a server that would dish up database connections, and then a client piece could connect to the server (on a different JVM), get a database connection, and use it to query a database.