Tenho duas aplicações diferentes e preciso trocar informações entre os Servlets delas.
Gostaria de saber se é possível e como se faz. Se alguém puder ajudar eu agradeço.
Tenho duas aplicações diferentes e preciso trocar informações entre os Servlets delas.
Gostaria de saber se é possível e como se faz. Se alguém puder ajudar eu agradeço.
Dá sim. O que tu precisa é abrir uma conexão entre ambas via URL:
String xml = "<damnit>damnit!!!</damnit>";
URL url = new URL("http://localhost/APP/servlet");
URLConnection con = url.openConnection();
con.setDoInput(true);
con.setDoOutput(true);
con.setRequestProperty("Content=length", xml.length());
// writing the request...
OutputStream out = con.getOutputStream();
out.write(xml.getBytes());
out.flush();
// read response from servlet...
BufferedReader in = new BufferedReader(new InputStreamReader(con
.getInputStream()));
String aLine;
StringBuffer buffer = new StringBuffer();
while ((aLine = in.readLine()) != null) {
buffer.append(aLine);
}
in.close();
out.close();
return buffer.toString();
Espero que ajude, T+