title: File upload clearing in jsp
body: <p>The scenario is to upload and preview image for crop and save it. Every thing is working fine but when i'm uploading the image and press cancel the dialog for cropping and trying to upload another file its showing the previous image in preview as well. i.e previewing the previous and latest file both. I want only recent uploaded file. i.e want to clear the previous upload.</p>
  
  <p>Here is the jsp code:</p>
  
  <pre><code>      function imageHandler(e2)
                  {
                      document.getElementById("cropbox").src = e2.target.result;
  
                      initJcrop();
                      $("#dialog").dialog({
                          show: {
                              effect: "blind",
                              duration: 1000
                          }  ,
  
                          width:document.getElementById('cropbox').height
  
                      });
                  }
                  function readFile(e1){
  
                      var filename = document.getElementById('imageId').files[0];
                      var fr = new FileReader();
                      fr.readAsDataURL(filename);
                      fr.onload = imageHandler;
  
                      document.getElementById("isSubmit").value = "false";
                      // document.getElementById("postForm").submit();
                  }
  
  
  
                         &lt;span id="reuploadImg" &gt;&lt;html:file name="uf" property="file" size="37" onchange="readFile(this)"  styleId="imageId"  /&gt;&lt;/span&gt;
   &lt;div id="dialog" style="display: none" title="Preview"&gt;
                                  &lt;img id="cropbox"&gt;
                                  &lt;br/&gt;&lt;br/&gt;
                                  &lt;div style="width: 100%;text-align: center"&gt;
                                  &lt;input type="button" value="Save" 
  
      onclick="cropPic()" class="stdbutton"/&gt;
                                      &lt;input type="button" value="Cancel" onclick="closeDialog()" class="stdbutton"/&gt;                                &lt;/div&gt;
                                  &lt;/div&gt;
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/yxj4o.jpg" alt="screenshot of preview image screen"></p>