HttpClient httpClient = new HttpClient();
PostMethod postMethod = new PostMethod(uri);
String receiveMsg = null;
// 填入各个表单域的值
NameValuePair[] data = new NameValuePair[parameter0.length];
// 将表单的值放入postMethod中
for(int i=0;i<data.length;i++){
data[i] = new NameValuePair(parameter0[i], parameter1[i]);
}
postMethod.setRequestBody(data);
// 执行postMethod
try {
int statusCode = httpClient.executeMethod(postMethod);
// HttpClient对于要求接受后继服务的请求,象POST和PUT等不能自动处理转发 301或者302
if(statusCode == HttpStatus.SC_MOVED_PERMANENTLY||statusCode == HttpStatus.SC_MOVED_TEMPORARILY);
byte[] receiveData = postMethod.getResponseBody();
receiveMsg = new String(receiveData);
postMethod.releaseConnection();
} catch (HttpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
postMethod.releaseConnection();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
postMethod.releaseConnection();
}
postMethod.getResponseBody();我servlet中用什么形式发送这样的数据才能使其接到数据
或者JSP,还是使用框架,请高手指点~~~

解决方案 »

  1.   

    byte[] receiveData = postMethod.getResponseBody();
    这不是用postMethod.getResponseBody()接收服务端返回的信息吗???
    我想问的是服务端用什么形式返回信息和这个方式对应上!
    我试了dos.write(byte[]);
    dos.writeUTF();
    都接不到...
    比如说
    dataoutputstream dos = ...
    dos.writeUTF("msg");
    那我们接不是
    dis.readUTF();么?
    就这样...
      

  2.   

    就是httpresponse,write的,和web的一样就可以了
    也可以用post.getResponseBodyAsString()获取文本内容
      

  3.   

    servlet跳转到jsp,或者直接返回html都可以,httpClient可以接受到返回网页的源代码
      

  4.   

    out=response.getWriter();
    out.print(...);
    out.print(...);
    ...
    out.print(...);
    out.close();
      

  5.   

    晕,直接用response.getWriter(); 这个可以,我试试看...
    开始没有想到~~~
      

  6.   

    OutputStream outputStreamClientResponse = httpServletResponse.getOutputStream();
    byte[] buffer = new byte[1024];
    //buffer 中是你要发送的数据
    outputStreamClientResponse.write(buffer);
      

  7.   

    或者用
    String arg0 = "";//你要发送的数据
    httpServletResponse.getWriter().write(arg0)