GeeCON Prague 2014*
The moose likes Tomcat and the fly likes Access a resource in different context Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Products » Tomcat
Bookmark "Access a resource in different context" Watch "Access a resource in different context" New topic
Author

Access a resource in different context

KRK Gowda
Ranch Hand

Joined: Nov 02, 2004
Posts: 132
Hi all,
I have 2 contexts. in one context, i am uploading a file. In other context, i have written a servlet to access uploaded file and download it to local machine. But i am stuck at how to access resource in different context but on same application server.

Please tell me a solution for this.


Thanks and Regards,
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
http://www.coderanch.com/t/364150/Servlets/java/forward-different-context
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

It seems, from what you've written, that these two servlets should be in the same context.

That being said Servlet.getServletContext(contextName) can get you access to another context within the same server. The spec does not go into a lot of detail on the subject of cross context interaction so I would expect inconsistent behavior among different containers. Tomcat, for instance disables this, by default. To enable this capability, see the crossContext attribute on this page:
http://tomcat.apache.org/tomcat-5.5-doc/config/context.html


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Raghavendra Nittur
Greenhorn

Joined: Feb 19, 2007
Posts: 29
Originally posted by Ben Souther:
Servlet.getServletContext(contextName) can get you access to another context within the same server. Tomcat, for instance disables this, by default. To enable this capability, see the crossContext attribute on this page:
http://tomcat.apache.org/tomcat-5.5-doc/config/context.html


Hi ben, I have gone through the link. Am unable to find the file in which i could set this attribute to true. am using tomcat 5.5.20.

Regards, Raghav
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Since this thread is now about configuring Tomcat, moving to the Apache / Tomcat forum.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

There are several ways to deploy a webapp in Tomcat.
The simplest is just to drop a war file or proper directory structure under the webapps directory. If you want to configure your application to use something other than the default settings, you might want to look at some of the other ways.

In older versions, you would enter a <Context ... /> node in tomcat/conf/server.xml. In newer versions, you would enter this xml node in it's own text file (context fragment file) with the name of your application + the ".xml" extension, and place it under the tomcat/conf/Catalina/localhost directory.

It is in this node that you would set the crossContext attribute.
Raghavendra Nittur
Greenhorn

Joined: Feb 19, 2007
Posts: 29
Thanks ben,

Am able to invoke resource in another app.

corssContext is Working......!!!

Regards, Raghav
 
GeeCON Prague 2014
 
subject: Access a resource in different context