0

How can Servlet1 from one application talk with Servlet2 deployed on another application on the same server

  • http://blog.imaginea.com/cross-context-communication-between-web-applications/ – Uooo Apr 08 '14 at 08:04
  • Define "talk". What do you want to achieve? Not technically, what are you making? What will the user experience? – Gimby Apr 08 '14 at 08:13
  • I mean request; once processed by servlet1, needs to call Servlet2 from some other application that is deployed on the same server as the application of Servlet1. – user3509948 Apr 08 '14 at 09:23

1 Answers1

0

You can use URLConnection to call your servlet resides in another application on same server or other server.
To call servlet you need to pass URL of that servlet, you can pass query parameter to servlet and read resonse from that servlet.
for more information please check below link
How to use URLConnection

Sample Code :

URLConnection connection = new URL("Servlet URL" ).openConnection(); //Connect to servlet
connection.setDoOutput(true); // used to call POST method
connection.setRequestProperty("Accept-Charset", "UTF-8");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + "UTF-8");
OutputStream output = connection.getOutputStream(); // send query parameter to request
try {
     output.write("test=testing".getBytes("UTF-8"));
} finally {
     try { output.close(); } catch (IOException logOrIgnore) {}
}
InputStream is = connection.getInputStream();    
// Read your servlet response.  
Community
  • 1
  • 1
Yagnesh Agola
  • 4,330
  • 5
  • 33
  • 50