Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to upload files to server using JSP/Servlet?
    text
    copied!<p>How can I upload files to server using JSP/Servlet? I tried this:</p> <pre class="lang-html prettyprint-override"><code>&lt;form action="upload" method="post"&gt; &lt;input type="text" name="description" /&gt; &lt;input type="file" name="file" /&gt; &lt;input type="submit" /&gt; &lt;/form&gt; </code></pre> <p>However, I only get the file name, not the file content. When I add <code>enctype="multipart/form-data"</code> to the <code>&lt;form&gt;</code>, then <code>request.getParameter()</code> returns <code>null</code>. </p> <p>During research I stumbled upon <a href="http://commons.apache.org/fileupload" rel="noreferrer">Apache Common FileUpload</a>. I tried this:</p> <pre><code>FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List items = upload.parseRequest(request); // This line is where it died. </code></pre> <p>Unfortunately, the servlet threw an exception without a clear message and cause. Here is the stacktrace:</p> <pre><code>SEVERE: Servlet.service() for servlet UploadServlet threw exception javax.servlet.ServletException: Servlet execution threw an exception at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:313) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:637) </code></pre>
 

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