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?
Hi, should work as the documentations say: getContext 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. Parameters: uripath - a String specifying the context path of another web application in the container. Returns: 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: RequestDispatcher but I�ve never tryied, the best way to discover is trying it. regards.
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.