title: sending input value in a jsp multipart/form-data form to a servlet
body: <p>I have a JSP containing a form</p>
  
  <pre><code>        &lt;form action="upload" method="post" enctype="multipart/form-data"&gt;
          &lt;fieldset&gt;
              &lt;input name="nom" class="input-xlarge focused" id="nom" type="text" value=""&gt; 
              &lt;input name="date" class="input-xlarge focused" id="date" type="text" value=""&gt;
              &lt;input type="file" name="file" /&gt; 
              &lt;button type="submit" class="btn btn-primary"&gt;Envoi&lt;/button&gt;
          &lt;/fieldset&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>which contains 2 fields (nom and date) and also asking for a file to be uploaded on the server.</p>
  
  <p>on the servlet side, I have the following:</p>
  
  <pre><code>    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  
      String UPLOAD_DIRECTORY = request.getServletContext().getRealPath("/")+"imgs/";
      //process only if its multipart content
      if(ServletFileUpload.isMultipartContent(request)){
  
          String nom = request.getParameter("nom");
          String date = request.getParameter("date");
          log.debug("upload parameters: "+nom+" "+date);
  
  
          try {
              List&lt;FileItem&gt; multiparts = new ServletFileUpload(
                                       new DiskFileItemFactory()).parseRequest(request);
  
              for(FileItem item : multiparts){
                  if(!item.isFormField()){
                      String name = new File(item.getName()).getName();
                      item.write( new File(UPLOAD_DIRECTORY + File.separator + name));
                  }
              }
  
             //File uploaded successfully
             request.setAttribute("message", "File Uploaded Successfully");
             log.debug("File updated successfully");
          } catch (Exception ex) {
             request.setAttribute("message", "File Upload Failed due to " + ex);
             log.debug("File upload failed: "+ex);
          }          
  
      }else{
          request.setAttribute("message",
                               "Sorry this Servlet only handles file upload request");
          log.debug("file upload only !");
      }
  
      //request.getRequestDispatcher("/result.jsp").forward(request, response);
  
  }
  </code></pre>
  
  <p>file upload is working properly but I'm not able to retrieve my two parameters (nom and date) by using request.getParameter.</p>
  
  <p>Can I retrieve parameters in a multipart/form-data ? how can I do that ?</p>