奇怪!!!!!HttpServletRequest的getInputStream()方法?????

grant999 2007-04-03 10:20:30
通过表单向一个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()) ;

这是为什么啊
...全文
226 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Squall1009 2007-04-04
  • 打赏
  • 举报
回复
available

public 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.

62,634

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧