3

I have deployed two WAR's in a Tomcat6 server, Say for example WAR-A, WAR-B in Context-A and Context-B respectively.

I've stored some data in Context-A, and I want to read that data in Context-B.

I have gone through the net and got some way to acheive it. I make the session ID of Context-A available for all the contexts by cookies. And I have set the crossContext = true in server.xml too.

But when I do serveltContext.getContext("Context-A"); in Context-B it's returning null.

1 Answer 1

3

The "Context-A" is incorrect. The parameter passed to getContext is a "uripath". So if you have WAR-A (/war-a) and WAR-B (/war-b) the call from WAR-B should be

servletContext.getContext("/war-a");

Note: the link I posted for getContext was from the Java EE 1.3 API, but it should not have changed.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks Dave,I did what you have suggested, But still the same,it didnt work.Am I missing any configuration
Murugesh - I'm checking into this now with a simple application ... I'll have an answer for you hopefully in the next 30 minutes.
@Murugesh when you say you set "crossContext" in the server.xml, which application did you set that on? It has to be set on the application requesting cross context access. So in your case, you need to set crossContext on the context for Context-B. I just found this empirical testing.
I didnt set this at a application specific level,I've added like this.I thought it ll be applicable all the Web App's that run on the server!Correct me if I wrong.Note: I've added only the context entry rest are by default available. <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <Context crossContext="true" /> </Host>
@Murugesh I don't think you can do that. A "Context" represents a single web application deployed on the host. By declaring a context as you have, that will not set crossContext="true" for all webapps. What you can do is create a META-INF/context.xml for the Context-B application (placing the META-INF directory at the same level as WEB-INF) and declare the context information there. I don't know specifically how this will behave, but you might have more luck doing that.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.