title: How to accept both multipart and application/x-www-form-urlencoded?
body: <p>I built a servlet that allows uploading a file or alternatively uploading a list as input. So far I've handled it by setting the servlet to accept multipart/form-data so even if there is no file, I read the list as a part.</p>
  
  <p>I'm now trying to call this servlet to upload a list through a JQuery AJAX method instead of through a form. If I try to upload a list normally through the method, I get:</p>
  
  <pre><code>org.apache.tomcat.util.http.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is application/x-www-form-urlencoded; charset=UTF-8
  </code></pre>
  
  <p>If I set the contentType as multipart/form-data like so:</p>
  
  <pre><code>$.ajax({    
      url: someUrl, 
      type: 'POST', 
      contentType: 'multipart/form-data', 
      data: {list: inputList}
  });
  </code></pre>
  
  <p>I get this error instead:</p>
  
  <pre><code>org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found
  </code></pre>
  
  <p>My question is if there is some way to configure the servlet to accept both content types or alternatively is there some way to write the ajax data to upload multipart/form-data?</p>
  
  <p>I know it's simple to upload multipart/form-data using the FormData API, but I need to support IE9 so this is not an option.</p>