• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

ServletContext

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 321
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 am Arthur, King of the Britons. And this is a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic