[英]Calling Servlets on same server but different applications?
一个应用程序中的Servlet1如何与部署在同一服务器上另一应用程序中的Servlet2进行通信
您可以使用URLConnection调用驻留在同一服务器或其他服务器上的另一个应用程序中的servlet。
要调用servlet,您需要传递该servlet的URL,可以将查询参数传递给servlet并从该servlet读取共振。
有关更多信息,请检查以下链接
如何使用URLConnection
样例代码:
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.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.