Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing variables between 2 wars

 
Amy N. Snow
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)???
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, there are lots of ways.
Which is best depends on what you're doing.

Can you describe the scenario in which you want to pass values from one webapp to another?
 
Amy N. Snow
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Ben,

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.
 
Anirvan Majumdar
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Hope this helps.
-Ben
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jayant Kr
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65535
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Jayant Kr", please check your private messages for an important administrative matter.
 
Anirudh Vyas
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here we go, I was waiting for someone to post this ... no one did. Sharing Session Data

Although the above is a violation of servlet spec.


Regards
Vyas, Anirudh
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!