title: Why can't upload three files with FileUpload?
body: <p>i'm trying to upload three images to my server, is working, but upload always the last file selected by the user, not the three selected.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>protected void doPost(HttpServletRequest request, HttpServletResponse response){
      boolean multipart = ServletFileUpload.isMultipartContent(request);
  
      if (multipart) {
          DiskFileItemFactory fileItemFactory = new DiskFileItemFactory();
  
          fileItemFactory.setSizeThreshold(5 * 1024 * 1024); //5 MB
          fileItemFactory.setRepository(tmpDir);
  
          ServletFileUpload uploadHandler = new ServletFileUpload(fileItemFactory);
          try {
              List items = uploadHandler.parseRequest(request);
  
              Iterator itr = items.iterator();
  
              while (itr.hasNext()) {
                  FileItem item = (FileItem) itr.next();
  
                  File file = new File(dir, generateNewName());
                  item.write(file);
              }
          } catch (FileUploadException ex) {
          } catch (Exception ex) {
          }
      }
  }
  </code></pre>
  
  <p>--
  UPDATE:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;Upload&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;form action="Upload" method="post" enctype="multipart/form-data"&gt;
              &lt;input type="file" name="file1" /&gt;
              &lt;br /&gt;
  
              &lt;input type="file" name="file2" /&gt;
              &lt;br /&gt;
  
              &lt;input type="file" name="file3" /&gt;
              &lt;br /&gt;
  
              &lt;input type="submit" value="Enviar" /&gt;
  
          &lt;/form&gt;
      &lt;/body&gt;
  </code></pre>
  
  <h2>    </h2>
  
  <p>UPDATE 2:</p>
  
  <p>I found my error:
  when i called the method <code>generateNewName()</code>  return a string that contains (date)+(hour)+(miliseconds) , i think this should be enough to generate a new name every time but returns the same name always, so this way rewrite the same file every time.</p>
  
  <p>Sorry for any inconvenience and thank you guys by the help.</p>
  
  <p>Best regards,
  Valter Henrique.</p>