OK, ServletContext and InitialContext are very different things.
In a web container, each web application is associated with a context, and all resources contained within a web application exist relative to its context. For example if we have a store application, it could exist under the context /store. Therefore if the application contained a file called cart.jsp if would be accessible at
http://localhost:8080/store/cart.jsp. Each context that exists in a web container, has a special object called a ServletContext associated with it. The ServletContext represents the web applications view on the container that it is deployed within. The ServletContext allows
servlets to access resources available to them in the container. The ServletContext can be thought of as a Sandbox for a web application. This sandbox allows us to have all of the benefits of isolating web applications that we mentioned above (no name clashes, and efficient easy classloading without having to set a classpath.)
The servlet context can be used to accomplish many tasks in a web application, but perhaps its primary uses are for sharing attributes between all of the servlets in an application, and for loading resources for use within the application. We also define application initialization parameters using the ServletContext, this is discussed in the section relating to deployment descriptors.
On the other hand, the InitialContext allows you to get a reference to the JNDI (or other naming service) naming service that is running on a given server (specified when you create the initial context.) This allows you to look up EJBs and other resources (JMS queues etc) that are stored in the JNDI (or other naming service)tree.
The <resource-ref> tag is used to abstract the name used in an
EJB to reference anothe EJB from the JNDI name under which the bean is deployed. Check this
thread for more details.
Hope this helps
Cheers
Sam