How do I pass objects between two servlets?

I am new to servlet programming. I want to know that ... is it possible to pass objects between two servlets located on different application servers ??? let's say two tomcat servers ...

means what I want to do: [browser] → [application server 1 does some operation on the data] → [server 2 does some operation on the data]

I'm sure this is possible, but can anyone tell me how?

+2


a source to share


2 answers


Except for server clustering (which you don't want to go into at this point, trust me), the only way to do this is to send a redirect from the first server to another, encoding the data you want to send to the url.

You cannot pass the actual object, since the servlets are on different servers, so data transfer is the best you can manage.



If you enjoy playing with Tomcat clusters, this gives you the ability to store objects in an HTTP session that are replicated across all servers in the cluster. I would definitely categorize this as "advanced use", although not something to get into if you're new to this.

+1


a source


If they are on two different servers, you can "duplicate" the original HttpServletRequest that was made for the first server / servlet. This can be done by opening a URLConnection to another server / servlet and copying the data from the first request to its outputStream.



0


a source







All Articles