从另一个应用程序的servlet调用servlet post方法

时间:2012-10-03 04:10:41

标签: java servlet-3.0

我想从另一个应用程序调用servlet POST方法,我在其中传递请求和响应。谁能告诉我这怎么可能?

1 个答案:

答案 0 :(得分:0)

如果在HTTP POST中调用了servlet,那么你可以对另一个servlet执行HTTP 307 redirect,它将调用它的doPost。如果要从servlet(或任何Java方法)POST到不同的页面,可以使用类似HttpClient之类的内容编写POST:

PostMethod post = new PostMethod("http://jakarata.apache.org/");
NameValuePair[] data = {
  new NameValuePair("user", "joe"),
  new NameValuePair("password", "bloggs")
};
post.setRequestBody(data);
// execute method and handle any error responses.
...
InputStream in = post.getResponseBodyAsStream();
相关问题