• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Inter-Servlet Communication

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm writing two servlets, and I would like one to call the other.
Each one will reside on seperate machines.

Let's call them servlet1 and servlet2. servlet1 needs to pass a file
to servlet2. So I'd like to call up servlet2's doPost method and pass
in the file that way. Then when servlet2 is finished doing its work,
it needs to pass back a different file that it has created. So I'm
thinking I would just dump the return file into the response and that
would come back to servlet1. Is that the most sensible way to do it?
If not, please enlighten me! If so, can anybody point me in the right
direction with code examples?

I've gotten as far as using a URL connection object to open the connection between servlets. Now I just need to be able to grab the response from servlet2 and copy it to the response servlet1 is going to send to the client.

Thanks in advance,
-Ryan
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

For transferring files, I'd use Jakarta Commons HttpClient on the client side, and Jakarta Commons FileUpload on the server side. Some information about how that can work can be found at the FileUpload FAQ page.

Instead of using this approach I'd rather use an FTP server that's accessible by both servlets, though, and just use a quick HTTP call to let the receiving side know that something new has been uploaded. That decouples things a bit, allowing both sides to work at different speeds. (Unless your application needs the synchronicity.)
 
Well THAT's new! Comfort me, reliable tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic