Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>&lt;div class="file" &gt; &lt;ul class="thumbnails"&gt; &lt;li class="span4"&gt; &lt;a href="#" class="thumbnail"&gt; &lt;div id="imgThumbId"&gt;&lt;/div&gt; &lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;form action="advertise.jsp" enctype="multipart/form-data"&gt; &lt;fieldset&gt; &lt;legend&gt;Upload Image&lt;/legend&gt; &lt;label for="file"&gt;Choose photo&lt;/label&gt; &lt;input type="file" name="file" id="file" /&gt;&lt;br/&gt; &lt;input type="submit" name="upload" id="upload" value="Upload photo" onclick="PreviewRecipeImage();"/&gt; &lt;/fieldset&gt; &lt;/form&gt; &lt;/div&gt; </code></pre> <p>Use <code>enctype="multipart/form-data"</code> in form.</p> <p>To handle multipart/form-data, use following servlet code. And also import <a href="http://commons.apache.org/fileupload/" rel="nofollow"> Apache Commons FileUpload </a> package in your code.</p> <pre><code>protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { List&lt;FileItem&gt; items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); for (FileItem item : items) { if (item.isFormField()) { // Process regular form field (input type="text|radio|checkbox|etc", select, etc). String fieldname = item.getFieldName(); String fieldvalue = item.getString(); // ... (do your job here) } else { // Process form file field (input type="file"). String fieldname = item.getFieldName(); String filename = FilenameUtils.getName(item.getName()); InputStream filecontent = item.getInputStream(); // ... (do your job here) } } } catch (FileUploadException e) { throw new ServletException("Cannot parse multipart request.", e); } // ... } </code></pre>
    singulars
    1. This table or related slice is empty.
    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. 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