For what I understand the sesssion cannot be shared between 2 wars when they are not deployed on the same EAR. But is there any way to pass one variable from a session to another session?
Is there any way to pass variables between 2 wars (one webapp is invoking a servlet on another webapp)???
Well, webapp1 is going to invoke a servlet of webapp2 and webapp 2 is going to perform some database queries. Webapp2 needs to pass some query results to webapp1. Both apps would be on the same app server which will probably be Webshere. Webapp1 is already constructed (its main architecture) so changes on that app should be minimal.
You could always transform the resultset structure to an XML string and write it into the response body when webapp2's servlet returns the response to webapp1's call.
If the interaction between the 2 webapp's is going to be quite extensive, you might even want to consider implementing XMLRPC between the two. It'll take you about half a day to understand the concepts and another half to implement it. Here's a tutorial which might come in handy.
The simplest thing to do is pass these values as querystring or post parameters. As Anirvan mentions, you could respond with XML or some other form of structured data.
The cross context sharing of data is possible between different webapps in the same container but the spec doesn't go into a lot of detail about how it should be implemented. So, the implementation will vary from container to container. You might want to go through your container's documentation to see what it offers in this respect.
Another approach is to read and write to a shared database or (if both web applications are on the same machine, file system).
There are a lot of other technologies offered by Java for interaction between applications. A few are RMI, RPC, SOAP, and JMS. Google is your best friend when researching these.
Originally posted by Ben Souther: There are a lot of other technologies offered by Java for interaction between applications. A few are RMI, RPC, SOAP, and JMS. Google is your best friend when researching these.
This was going to be my suggestion. It sounds like you need to look at some kind of middleware, and it better to do this in a professional manner than trying to solve the problem purely on the servlet tier.
I would pull the values first from servelet A, and then pass it back to servlet B either as hidden form fields or with querystring. Unless I am a consultant and want to make things complex, I would not do Web Services/ RPC or anything like that.