Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>HTML file uploads use by default <a href="http://www.faqs.org/rfcs/rfc2388.html" rel="nofollow noreferrer">the <code>multipart/form-data</code> request encoding</a> (this is in order to be able to upload multiple files and/or to mix normal input field values in <strong>one</strong> request). You're however not parsing and extracting the individual form data parts from the request body, instead you're reading and writing the <em>entire</em> request body plain unmodified to a file. </p> <pre><code>is = request.getInputStream(); fos = new FileOutputStream(new File(realPath + "/" + filename), false); IOUtils.copy(is, fos); </code></pre> <p>This is indeed not ever going to work. That you said that it works in FF/Chrome is beyond me. Perhaps you're misinterpreting the results or do not have tested it in those browsers with binary files at all.</p> <p>You need to use <a href="http://commons.apache.org/fileupload" rel="nofollow noreferrer">Apache Commons FileUpload</a> to extract the parts from a <code>multipart/form-data</code> request. Or, when you're already on Servlet 3.0, you could also use the Servlet API provided <a href="http://download.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getParts%28%29" rel="nofollow noreferrer"><code>HttpServletRequest#getParts()</code></a> method.</p> <h3>See also:</h3> <ul> <li><a href="https://stackoverflow.com/questions/2422468/how-to-upload-files-in-jsp-servlet/2424824#2424824">How to upload files to server using JSP/Servlet?</a></li> <li><a href="https://stackoverflow.com/questions/7114087/html5-file-upload-to-java-servlet">HTML5 File Upload to Java Servlet</a></li> </ul> <hr> <p><strong>Unrelated</strong> to the concrete problem, you've another problem with the code posted so far. You're storing uploaded files in the web content of the expanded WAR. This is far from a solid permanent storage location. Everytime when you redeploy a new WAR, all those files will get lost. You'd need to backup them everytime which is plain clumsy and error prone. Rather store them in a fixed location outside the expanded WAR folder.</p> <h3>See also:</h3> <ul> <li><a href="https://stackoverflow.com/questions/7274517/java-ee-best-way-to-get-real-path-to-uploaded-files">Java EE - Best way to get real path to uploaded files?</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload