文件上传

来源:互联网 发布:长春网络广播电视台 编辑:程序博客网 时间:2024/04/30 23:37

文件上传历史:1995年11月发布的RFC1867规范(即HTML中基于表单的文件上传)对表单做出了扩展。

eg: 

  <form action="" method="post" enctype="multipart/form-data">

http:请求消息:

 POST URL HTTP/1.1

 ...

 Content-Type:multipart/form-data;boundary=journey

 ...

  Content-Length:

 ...

  Cache-Control:no

  (CRLF)

--journey

Content-Disposition:form-data;name="file1";filename="f:"

Content-Type:text/plain

(CRLF)

hello word!

--journey--

 

 

注意:

  对于文件上传来说,要读取文件的内容,不能使用ServletRequest接口的getParameter()方法,而需要调用ServletRequest接口的getInputStream()方法来得到输入流,然后从输入流中读取传送的内容,再根据文件上传的格式进行分析,取出上传文件的内容和其他字段内容。