title: The method getPart(String) is undefined for the type HttpServletRequest
body: <p>I have been working on Java web project in which i need to upload an image through the JSP page and store it into a MySQL database.
  I'm entering the image in multiparts which is available for Servlet 3.0 or above.</p>
  
  <p>I've been using the getPart("image") to get the image part by part but it's showing me the following error:
  <strong>"The method getPart(String) is undefined for the type HttpServletRequest"</strong></p>
  
  <ul>
  <li>The server i'm using: Tomcat 7</li>
  <li>The IDE i'm using: Eclipse Luna</li>
  </ul>
  
  <p><strong>Here are the code snippets:</strong></p>
  
  <p><strong>ImageUploadServlet:</strong></p>
  
  <pre><code>package com.nagarro.imagemanagementutility.controller;
  
  import java.io.IOException;
  import java.io.InputStream;
  
  import javax.servlet.ServletException;
  import javax.servlet.annotation.MultipartConfig;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.Part;
  
  import com.nagarro.imagemanagementutility.util.Constants;
  
  /**
  * Servlet implementation class ImageUploadServlet
  */
  @MultipartConfig(maxFileSize=Constants.MAX_FILE_SIZE)   // Upload image file     size upto 16 MB
  public class ImageUploadServlet extends HttpServlet {
  private static final long serialVersionUID = 1L;
  
  /**
   * @see HttpServlet#HttpServlet()
   */
  public ImageUploadServlet() {
      super();
  }
  
  /**
   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  
      InputStream inputStream = null;
  
      // obtains the upload image file in this multipart request
      Part imagePart = request.getPart("photo");
  }
  
  }
  </code></pre>
  
  <p><strong>UserImageUtility.jsp</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
   pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Image Management Utility&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
   &lt;table border="1" align="center" width="900px"&gt;
    &lt;tr&gt;
     &lt;td&gt;
      &lt;div align="center"&gt;
       &lt;h3&gt;Image Management Utility&lt;/h3&gt;
      &lt;/div&gt;
     &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
     &lt;td&gt;
      &lt;div&gt;Please select an image file to upload (Max Size 1 MB)&lt;/div&gt;
      &amp;nbsp;
      &lt;form action="ImageUploadServlet" method="post"
       enctype="multipart/form-data"&gt;
       &lt;input type="file" name="image" size="50" /&gt;
       &lt;div align="right"&gt;
        &lt;input type="submit" name="sbtnSubmit" value="Submit" /&gt;
        &lt;input type="button" name="btnCancel" value="Cancel" /&gt;
       &lt;/div&gt;
      &lt;/form&gt;
     &lt;/td&gt;
    &lt;/tr&gt;
   &lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>pom.xml:</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
   &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
   &lt;groupId&gt;com.nagarro&lt;/groupId&gt;
   &lt;artifactId&gt;Assignment_4_ImageManagementUtility&lt;/artifactId&gt;
   &lt;packaging&gt;war&lt;/packaging&gt;
   &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
   &lt;name&gt;Assignment_4_ImageManagementUtility Maven Webapp&lt;/name&gt;
   &lt;url&gt;http://maven.apache.org&lt;/url&gt;
  
   &lt;build&gt;
    &lt;finalName&gt;Assignment_4_ImageManagementUtility&lt;/finalName&gt;
    &lt;pluginManagement&gt;
     &lt;plugins&gt;
      &lt;plugin&gt;
       &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
       &lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt;
       &lt;configuration&gt;
        &lt;archive&gt;
         &lt;manifest&gt;
          &lt;addClasspath&gt;true&lt;/addClasspath&gt;
          &lt;classpathPrefix&gt;lib/&lt;/classpathPrefix&gt;
          &lt;mainClass&gt;com.nagarro.imagemanagementutility.controller.ApplicationLauncher&lt;/mainClass&gt;
         &lt;/manifest&gt;
         &lt;manifestEntries&gt;
          &lt;Class-Path&gt;.&lt;/Class-Path&gt;
         &lt;/manifestEntries&gt;
        &lt;/archive&gt;
  
        &lt;finalName&gt;&lt;/finalName&gt;
       &lt;/configuration&gt;
      &lt;/plugin&gt;
     &lt;/plugins&gt;
    &lt;/pluginManagement&gt;
   &lt;/build&gt;
  
   &lt;dependencies&gt;
    &lt;dependency&gt;
     &lt;groupId&gt;junit&lt;/groupId&gt;
     &lt;artifactId&gt;junit&lt;/artifactId&gt;
     &lt;version&gt;3.8.1&lt;/version&gt;
     &lt;scope&gt;test&lt;/scope&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
     &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
     &lt;artifactId&gt;servlet-api&lt;/artifactId&gt;
     &lt;version&gt;3.0-alpha-1&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
     &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
     &lt;artifactId&gt;jstl&lt;/artifactId&gt;
     &lt;version&gt;1.2&lt;/version&gt;
     &lt;scope&gt;runtime&lt;/scope&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
     &lt;groupId&gt;jstl&lt;/groupId&gt;
     &lt;artifactId&gt;jstl&lt;/artifactId&gt;
     &lt;version&gt;1.2&lt;/version&gt;
     &lt;scope&gt;provided&lt;/scope&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
     &lt;groupId&gt;javax.servlet.jsp.jstl&lt;/groupId&gt;
     &lt;artifactId&gt;jstl-api&lt;/artifactId&gt;
     &lt;version&gt;1.2&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
     &lt;groupId&gt;taglibs&lt;/groupId&gt;
     &lt;artifactId&gt;standard&lt;/artifactId&gt;
     &lt;version&gt;1.1.2&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
     &lt;groupId&gt;javax.persistence&lt;/groupId&gt;
     &lt;artifactId&gt;persistence-api&lt;/artifactId&gt;
     &lt;version&gt;1.0.2&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
     &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
     &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
     &lt;version&gt;4.3.8.Final&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
     &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
     &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
     &lt;version&gt;4.3.8.Final&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
     &lt;groupId&gt;postgresql&lt;/groupId&gt;
     &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
     &lt;version&gt;9.1-901-1.jdbc4&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;!-- Hibernate uses slf4j for logging --&gt;
    &lt;dependency&gt;
     &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
     &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
     &lt;version&gt;1.7.10&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
     &lt;groupId&gt;mysql&lt;/groupId&gt;
     &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
     &lt;version&gt;5.1.6&lt;/version&gt;
    &lt;/dependency&gt;
   &lt;/dependencies&gt;
  &lt;/project&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>The list of jar in the lib:</strong>
  <img src="https://i.stack.imgur.com/8mdmR.jpg" alt="The list of jars in the lib"></p>