File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes ServletContext Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "ServletContext" Watch "ServletContext" New topic


Samuel Giannotti

Joined: Nov 07, 2001
Posts: 4
Can I use the ServletContext method - public ServletContext getContext(java.lang.String uripath) - to get the ServletContext object from a servlet in the same WebServer, but running in a different web application?
Marcos Maia
Ranch Hand

Joined: Jan 06, 2001
Posts: 977
Hi, should work as the documentations say:
public ServletContext getContext(java.lang.String uripath)
Returns a ServletContext object that corresponds to a specified URL on the server.
This method allows servlets to gain access to the context for various parts of the server, and
as needed obtain RequestDispatcher objects from the context. The given path must be
begin with "/", is interpreted relative to the server's document root and is matched against the
context roots of other web applications hosted on this container.
In a security conscious environment, the servlet container may return null for a given URL.
uripath - a String specifying the context path of another web application in the
the ServletContext object that corresponds to the named URL, or null if either
none exists or the container wishes to restrict this access.
See Also:
but I�ve never tryied, the best way to discover is trying it.
Rishi Singh
Ranch Hand

Joined: Dec 09, 2000
Posts: 321
Hi Samuel,
Every web application running in a container has one ServletContext.Two possible scenarios can be visualized.
1)More than one web-application running in the same container, each having its own Servlet Context.In this case if u want to retrieve the servlet context object from a servlet which is not part of the web-application but running under the same container and part of another application, it is possible.
2)The same scenario but in different container is not possible as you have to make a remote call and for that your Servlet context object needs to be serialized.

I agree. Here's the link:
subject: ServletContext
It's not a secret anymore!