Servlet to Servlet Communication?
Hello,
I have a problem w/communicating data from one servlet to another.
In resin.conf:
<web-app id='C:\apps\mytestapp'/>
My two servlets reside in the declared web-app.
I have servlet1 that Posts data to an outside thirdpart (ie different domain) servlet. The third party servlet responds, posting data to my other servlet, servlet2.
Servlet2 receives data that I want to communicate back to Servlet1.
I have tried doing:
req.getSession().getServletContext().setAttribute(
"servlet2Data", myData);
That does not work. I see that the session IDs are different.
The data is sensitive so, I need to be careful in how I pass it around.
Suggestions?
If you want to communicate from one Servlet to another, you normally POST to the other Servlet. If security is an issue, use SSL when posting. If you are using J5EE, the Servlet 2.5 spec allows Servlets to (finally) share context information. The code you posted would not work in 2.5, but converting it to work would involve only a few small changes. Another option (if J5EE is not viable) would be to use a vendor-specific solution, such as Tomcat's cross-context sharing ability. Finally, if both Servlets can access the same database, store the results in the database and then provide a mechanism whereby the other Servlet can be notified to pick up the data.
- Saish
Saisha at 2007-7-14 17:30:19 >
