现在的位置: 首页 > 综合 > 正文

文件上传

2013年12月01日 ⁄ 综合 ⁄ 共 516字 ⁄ 字号 评论关闭

文件上传历史: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()方法来得到输入流,然后从输入流中读取传送的内容,再根据文件上传的格式进行分析,取出上传文件的内容和其他字段内容。

 

 

抱歉!评论已关闭.