title: JSP identify duplicate file upload
body: <p>I've been seraching for this for quite a long time, but found no good answer.</p>
  
  <p>I have four  fields which accept files from user, </p>
  
  <pre><code>&lt;form method="post" action="upload" target="_blank" enctype="multipart/form-data" style="position: absolute; right: 0%; top: 2%;"&gt;
  Left File :  &lt;input type="file" name="dataFile" id="fileChooser" /&gt;&lt;br&gt;&lt;br&gt;
  Right File : &lt;input type="file" name="dataFile" id="fileChooser" /&gt;&lt;br&gt;&lt;br&gt;
  Config File :&lt;input type="file" name="dataFile" id="fileChooser" /&gt;&lt;br&gt;&lt;br&gt;
  my File :  &lt;input type="file" name="dataFile" id="fileChooser" /&gt;&lt;br&gt;&lt;br&gt;
  upload&lt;input type="submit" value="Upload" multiple="multiple" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>how to identify if the user chooses to upload same file all the four times and prevent it (i.e duplicate uploads)? </p>
  
  <p>this may be on the JSP side or on the sevlet java side.
  Using commons file upload.
  I've found on my search <a href="https://stackoverflow.com/questions/3721572/best-way-to-detect-duplicate-uploaded-files-in-a-java-environment">here</a> that I need to use DigestOutputStream, but no where I could find how to use it and was of no use.</p>
  
  <p>---------------------------------------------EDIT--------------------------------------</p>
  
  <p>Based on the answers below, I've updated my code as follows,</p>
  
  <pre><code>&lt;form method="post" name="myform" action="upload" target="_blank" enctype="multipart/form-data" style="position: absolute; right: 0%; top: 2%;"&gt;
  Left File :  &lt;input type="file" name="dataFile1" id="fileChooser1" /&gt;&lt;br&gt;&lt;br&gt;
  Right File : &lt;input type="file" name="dataFile2" id="fileChooser2" /&gt;&lt;br&gt;&lt;br&gt;
  Config File :&lt;input type="file" name="dataFile3" id="fileChooser3" /&gt;&lt;br&gt;&lt;br&gt;
  Geco File :  &lt;input type="file" name="dataFile4" id="fileChooser4" /&gt;&lt;br&gt;&lt;br&gt;
  &lt;/form&gt;
  &lt;button type="button" onclick="ValidateFile()" style="position: absolute; right: 8%; top: 20%;"&gt;Click to Upload&lt;/button&gt;
  &lt;script type='text/javascript'&gt;
   function ValidateFile()
   {
  var FileName1 = document.getElementById("fileChooser1");
  var FileName2 = document.getElementById("fileChooser2");
  var FileName3 = document.getElementById("fileChooser3");
  var FileName4 = document.getElementById("fileChooser4");
  
  if(FileName1 == FileName2)
      {
          alert("Same file cannot be uploaded!");
      }
  
          document.myform.submit(); // This works fine, but the alert doesn't. Tried .value and .value() also still doesn't work.     
   }
   &lt;/script&gt;
  </code></pre>
  
  <p>Still the code doesn't work what is my mistake?</p>