title: Wicket and AJAX : Upload file to server and show it on page
body: <p>My web application is running on tomcat6 and I'm using <strong>Wicket</strong> to develop it.
  What I'm trying to do is to upload image file to the server and display it on web page as soon as it will be uploaded. I'm uploading file via AJAX as described <a href="http://www.wicket-library.com/wicket-examples/ajax/upload?1" rel="nofollow">here</a>. The file is uploaded it is stored on disk in <code>/home/mysuser/</code> path. When the file is uploaded, I'm executing JavaScript in order to load that file in to HTML object with:</p>
  
  <p>Wicket code:</p>
  
  <pre><code>protected void onSubmit(AjaxRequestTarget target, Form&lt;?&gt; form)
  {
      target.appendJavaScript("loadOriginalImage(\""+
                (UPLOAD_FOLDER + TMP_FILE_NAME1)+"\")");
  }
  </code></pre>
  
  <p>JavaScript code:</p>
  
  <pre><code>function loadOriginalImage(image_path){
     var curImg = new Image();
     curImg.src = "file://"+image_path;
     curImg.onload = function(){
        imgHolder.appendChild(this);   
     }
  }
  </code></pre>
  
  <p>The file is uploaded well, but when the JavaScript is executed, the next error appears:</p>
  
  <pre><code>Not allowed to load local resource
  </code></pre>
  
  <p>Then I've tried to remove <code>"file://"</code> from JavaScript code, as I've found that file is read from client's local folder and not from server's. But this time I've got next error:</p>
  
  <pre><code>GET http://localhost:8080/home/myuser/originalImg.jpg 404 (Not Found) 
  </code></pre>
  
  <p>So I have two questions:</p>
  
  <p><strong>1.</strong> How I specify in JavaScript the correct path of uploaded file?</p>
  
  <p><strong>2.</strong> Is my strategy is correct to load image to web page after uploading it to server? </p>