• Post Reply Bookmark Topic Watch Topic
  • New Topic

Forwarding same request to another Servlet

 
Nischal Tanna
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • 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 ..!!!
 
Marty Hall
Author
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • 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
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!