Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is <strong>not</strong> the right way to process a file upload in Servlet 3.0. You should instead be using <a href="http://docs.oracle.com/javaee/6/api/javax/servlet/annotation/MultipartConfig.html" rel="nofollow noreferrer"><code>@MultipartConfig</code></a> annotation on the servlet and be using <a href="http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getPart%28%29" rel="nofollow noreferrer"><code>HttpServletRequest#getPart()</code></a> method to obtain the uploaded file, which was introduced in Servlet 3.0.</p> <p>The <code>org.apache.tomcat.util.fileupload</code> package contains exactly those classes which are doing all "behind the scenes" work of this new Servlet 3.0 feature. You shouldn't be using them directly, like as that you shouldn't be using <code>sun.*</code> classes when using Java SE on a Sun/Oracle JVM, and that you shouldn't be using <code>com.mysql.*</code> classes when using JDBC on a MySQL DB. It seems that you got confused by examples targeted at Servlet 2.5 or older using <a href="http://commons.apache.org/fileupload" rel="nofollow noreferrer">Apache Commons FileUpload</a> which happens to use the same classnames.</p> <p>Using Tomcat-specific classes would tight-couple your webapp to the specific Tomcat version and makes your webapp <strong>unportable</strong> to other Servlet 3.0 compatible containers and even to a different Tomcat version as you encountered yourself. You should in this particular case stick to standard classes from the <code>javax.servlet</code> package.</p> <p>The right way is shown in the 2nd part of this answer: <a href="https://stackoverflow.com/questions/2422468/how-to-upload-files-to-server-using-jsp-servlet/2424824#2424824">How to upload files to server using JSP/Servlet?</a></p> <p>All with all, this kickoff example should get you started:</p> <pre class="lang-html prettyprint-override"><code>&lt;form action="upload" method="post" enctype="multipart/form-data"&gt; &lt;input type="text" name="status" /&gt; &lt;input type="file" name="uploadedFile" /&gt; &lt;input type="submit" /&gt; &lt;/form&gt; </code></pre> <p>with</p> <pre><code>@WebServlet("/upload") @MultipartConfig public class UploadServlet extends HttpServlet { @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String status = request.getParameter("status"); // Retrieves &lt;input type="text" name="status"&gt; Part uploadedFile = request.getPart("uploadedFile"); // Retrieves &lt;input type="file" name="uploadedFile"&gt; InputStream content = uploadedFile.getInputStream(); // ... (do your job here) } } </code></pre> <p>That's all.</p>
    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.
    3. 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