大家好,我从jsp页面post提交数据给Servlet,数据应该是都存在request对象中了,我现在想获取post头的完整信息,类似下面的:
POST /httpUpload/UploadServlet.do HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-silverlight, application/msword, application/vnd.ms-powerpoint, application/vnd.ms-excel, */*
Referer: http://localhost:8888/httpUpload/
Accept-Language: zh-cn
Content-Type: multipart/form-data; boundary=---------------------------7d9399301210c4
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 2.0.50727)
Host: localhost:8888
Content-Length: 72451
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: JSESSIONID=7778F1F023C647A63D7CB70B6AF76365-----------------------------7d9399301210c4
Content-Disposition: form-data; name="userfile1"; filename="E:\ucos_http_tftp\uC-HTTP\htm\data.dat"
Content-Type: application/octet-stream0 101 103 103 102 102 102 100
91 113 0 113 102 94 113 122
95 117 0 117 103 100 116 126 -----------------------------7d9399301210c4
Content-Disposition: form-data; name="text"zzzzzzzzzzzzzzzzzzzzzzzzzzz
-----------------------------7d9399301210c4--该怎么做?谢谢!

解决方案 »

  1.   

    我看了一下request的方法,好像只能获取某一部分的信息...
      

  2.   

    InputStream is = request.getInputStream();
    BufferedReader br = new BufferedReader(new InputStreamReader(is));
    String buffer = null;
    while((buffer=br.readLine()!=null)
     System.out.println(buffer);
      

  3.   

              谢谢myairland! 不过我刚才试了,这样只能获得后面的数据,前面的头信息没有包括在内.
                try {
    BufferedReader rd = new BufferedReader(new InputStreamReader(request.getInputStream(), "UTF-8"));
    String str;
        System.out.println("begin##########################");
    while((str=rd.readLine())!=null){
    System.out.println(str);
    }
    System.out.println("end##########################");
    } catch (UnsupportedEncodingException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    } catch (IOException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    }
      

  4.   

    request.getHeaderNames()然后自己迭代出来
      

  5.   

    Servlet中通过request对象好像搞不定。
    如果使用Socket就可以通过流读出来了,读取出来的就是一个完整的消息。
      

  6.   

    String getHeader(String name)Enumeration getHeaders(String name)Enumeration getHeaderNames()int getIntHeader(String name)你自己查下api,这些都带header,我没用过,估计可以解决你的问题.
      

  7.   

    to5楼:
    request.getInputStream()用这个不就可以读出流信息了。
      

  8.   

    用request.getHeaderNames() 得到所有的请求报头
    然后用request.getParameter(" ")或者request.getInputStream()得到表单的数据。
      

  9.   

    谢谢,用request.getHeaderNames() 感觉应该行,我试一下~~