通过表单向一个servlet的doPost方法提交请求,para=12345,doPost内容如下:
protected void doPost(HttpServletRequest arg0, httpServletResponse arg1) throws ServletException, IOException {

InputStream in=arg0.getInputStream();
byte[] b=new byte[in.available()];
in.read(b);
for(byte i : b){
System.out.println(i) ;
     }
}
本想从request输入流中读出内容到字节数组,但in.available()总是为0,迷惑!!
但是换成以下内容,就会输出 ”para=12345“:
InputStreamReader isr = new InputStreamReader (in);
BufferedReader br = new BufferedReader (isr);
             System.out.println(br.readLine()) ;这是为什么啊

解决方案 »

  1.   

    availablepublic int available()
                  throws IOException    Returns the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream. The next caller might be the same thread or another thread.    The available method for class InputStream always returns 0.    This method should be overridden by subclasses.    Returns:
            the number of bytes that can be read from this input stream without blocking. 
        Throws:
            IOException - if an I/O error occurs.