开发者

how to pass objects between two servlets?

开发者 https://www.devze.com 2022-12-29 21:47 出处:网络
i am new to servlet programming. i want to know that... is it possible to pass objects between two servlets residing on di开发者_开发问答fferent application servers??? say two tomcat servers...

i am new to servlet programming. i want to know that... is it possible to pass objects between two servlets residing on di开发者_开发问答fferent 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??


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消