1 public void doPost(HttpServletRequest request, HttpServletResponse response)
 2                         throws ServletException, IOException {
 3                 request.setCharacterEncoding("gbk");
 4                 PrintWriter out = response.getWriter();
 5                 //使用SaeUserInfo拿到改请求可写的路径
 6                 String realPath= SaeUserInfo.getSaeTmpPath()+"/"; 
 7                 try {
 8                         //使用common-upload上传文件至这个路径中
 9                      boolean isMultipart=ServletFileUpload.isMultipartContent(request);
10                      if(!isMultipart)return;
11                      DiskFileItemFactory factory=new DiskFileItemFactory();
12                      ServletFileUpload upload=new ServletFileUpload(factory);
13                      upload.setFileSizeMax(1024*1024);
14                      List<FileItem> items=null;
15                  items=upload.parseRequest(request);
16                      for(FileItem item:items)
17                      {
18                        if(!item.isFormField())
19                        {
20                           File fullFile=new File(item.getName());
21                           File uploadFile=new File(realPath,fullFile.getName());
22                       item.write(uploadFile);
23                       //上传完毕后 使用SaeStorage往storage里面写
24                       SaeStorage ss = new SaeStorage();
25                       //使用upload方法上传到域为image下
26                       ss.upload("image", realPath+fullFile.getName(), fullFile.getName());
27                       
28                       out.print("upload file:"+realPath+fullFile.getName()+"</br>");
29                        }
30                      }
31                      out.print("upload end...");
32                 } catch (Exception e) {
33                         out.print("ERROR:"+e.getMessage()+"</br>");
34                 } finally{
35                         out.flush();
36                         out.close();
37                 }
38         }
 1  <form action="FileUpload" method="post" enctype="multipart/form-data">
 2       <table>
 3         <tr>
 4           <td>请选择要上传的文件</td>
 5           <td>
 6              <input type="file"name="filepath"size="20"/>
 7            </td>
 8         </tr>
 9         <tr>
10            <td>
11              <input type="submit"value="上传"/>
12            </td>
13         </tr>
14        </table>
15    </form>

转载: http://saebbs.com/forum.php?mod=viewthread&tid=2367&highlight=Storage