title: Request.getPart is called without multipart jsp
body: <blockquote>
    <p>java.lang.IllegalStateException: Request.getPart is called without multipart configuration. Either add a @MultipartConfig to the servlet, or a multipart-config element to web.xml</p>
  </blockquote>
  
  <p>I am getting this error above when i try to add image to my project</p>
  
  <p>MY html is </p>
  
  <pre><code>&lt;form action="../include/crud.jsp" method="POST"&gt;
      &lt;input type='file' onchange="readURL(this);" style="display:none;" name="photo" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>My crud.jsp is</p>
  
  <pre><code>&lt;%@page import="java.text.DateFormat"%&gt;
  &lt;%@page import="java.text.SimpleDateFormat"%&gt;
  &lt;%@page import="java.sql.PreparedStatement"%&gt;
  &lt;%@ include file="dbconfig.jsp" %&gt;
  &lt;%@ page import="java.io.*,java.util.*, javax.servlet.*" %&gt;
  &lt;%@ page import="javax.swing.*" %&gt;
  &lt;%@page 
      import="org.apache.commons.fileupload.FileItem"
      import="org.apache.commons.fileupload.FileUploadException"
      import="org.apache.commons.fileupload.disk.DiskFileItemFactory"
      import="org.apache.commons.fileupload.servlet.ServletFileUpload"
  
  
      %&gt;
  
  &lt;% 
  
      Part filePart = request.getPart("photo"); // Retrieves &lt;input type="file" name="file"&gt;
      String fileName = filePart.getSubmittedFileName();
      InputStream fileContent = filePart.getInputStream();
  
      try {
          conn.setAutoCommit(false);
          PreparedStatement preparedStatement = null;
  
  
  
          String act = request.getParameter("btncrud");
          if (act == null) {
              //no button has been selected
          } else if (act.equals("Add")) {
              //Add button was pressed
  
  
              String add_disbursement = "INSERT INTO photo_table "
                                  + "(ri_photo,ri_photo_name)"
                                  + " VALUES (?,?)"; 
  
              preparedStatement.setBlob(1,fileContent);
              preparedStatement.setString(2,fileName);
  
              preparedStatement.executeUpdate();
  
          } else if (act.equals("Update")) {
              //update button was pressed
  
          } else {
              //someone has altered the HTML and sent a different value!
  
          }         
  %&gt;
  </code></pre>
  
  <ol>
  <li>How to get rid of the error</li>
  <li>How to save photo file in database as medium blob</li>
  </ol>
  
  <p><strong>FYI</strong></p>
  
  <p>Column <code>ri_photo</code> is of type mediumblob</p>
  
  <p><code>UPDATE</code></p>
  
  <p>ADDED <code>cos-multipart.jar</code> and <code>import=" com.oreilly.servlet.MultipartRequest"</code> still same error</p>
  
  <p>How to add <code>@MultipartConfig</code> in JSP page</p>