• 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

Forwarding same request to another Servlet

 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi..
is there ne way to send a request from a servlet on one server to another another page at another server.The request object should be the same ..!!!
 
Author
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Is there ne way to send a request from a servlet on one server to another another page at another server? The request object should be the same ..!!!


No. The fundamental point is that the request object corresponds to an HTTP request, so if you go to another server, it will have a different request object. Specifically:
  • RequestDispatcher.forward only works for resources on the same server.
  • response.sendRedirect results in a new network roundtrip, thus a new HTTP request, thus a new request object. However, you can embed information in the HTTP request parameters by embedding the info in the URL that you supply to response.sendRedirect. Of course, this info is in the form of strings, not arbitrary Java objects. The same goes for trying to use URL and URLConnection to talk to a remote server: you are speaking HTTP over the network so cannot directly pass the remote server your request object, but can supply data in the URL.
  • If the app on the remote server is specifically written to communicate with your app (ie it is not just an arbitrary servlet), there are more efficient means of communication. For example, you could use HTTP tunneling and send serialized Java objects, or you could even simply use RMI if the remote app was not using HTTP only. But, this is just asking "how can a Java application do networking to another Java application?" -- it is not really invoking a remote servlet directly.


  • Cheers-
    - Marty
     
    reply
      Bookmark Topic Watch Topic
    • New Topic