tags:

views:

72

answers:

2

hi,

i am new to servlet programming. i want to know that... is it possible to pass objects between two servlets residing on different application servers??? say two tomcat servers...

means what i want to do is: [browser]--> [app server 1 performs some operation on data]--> [server 2 does some operation on data]

i am sure it is possible but can anyone tell me how??

A: 

If they are on two different servers you might want to 'duplicate' the original HttpServletRequest that has been made to the first server/servlet. You can do that by opening URLConnection to the other server/servlet and copy data from the first one request to its outputStream.

Jaroslav Záruba
ohh... thanks a lot...!
rohit
+1  A: 

Short of server clustering (which you don't want to get into at this point, trust me), the only way to do this is to send a redirect from the first server to the other, encoding the data you want to send on to the URL.

You can't pass the actual object, since the servlets are on different servers, so passing data is the best you'll be able to manage.

If you do fancy playing with Tomcat clustering, then this gives the facility of storing objects in the HTTP session which are replicated across all servers in the cluster. I'd definitely categorise this is as "advanced usage", though, and not something to get into if you're new to this stuff.

skaffman