title: Image uploading issue in JSP
body: <p>I want to upload an image file in my project directory folder named <strong>Images</strong> and store the image name in a database. </p>
  
  <p>The file name has been saved in the database and my image retrieved by the browser properly, but when I check my directory folder named <strong>Images</strong> it is empty. </p>
  
  <p>My questions is: Where is my file stored and why can't I see the image file in my folder?</p>
  
  <p><strong>This is my Index.jsp file</strong></p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;%-- 
      Document   : index
      Created on : Mar 15, 2018, 7:30:15 PM
      Author     : Lenovo
  --%&gt;
  
  &lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;JSP Page&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
  
          &lt;form name="form1" method="post" enctype="multipart/form-data" action="insertimage.jsp"&gt;
  
          &lt;p&gt;
          &lt;input type="file" name="ImageFile" id="ImageFile" /&gt;
          &lt;/p&gt;
          &lt;p&gt;
          &lt;input type="submit" name="submit" value="submit" /&gt;
          &lt;/p&gt;
          &lt;/form&gt;
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>This is my insertimage.jsp file</strong></p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;%@ page import="org.apache.commons.fileupload.servlet.ServletFileUpload" %&gt;
  &lt;%@ page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%&gt;
  &lt;%@ page import="org.apache.commons.fileupload.*"%&gt;
  &lt;%@ page import="java.util.*, java.io.*" %&gt;
  &lt;%@ page import="java.util.Iterator"%&gt;
  &lt;%@ page import="java.util.List"%&gt;
  &lt;%@ page import="java.io.File"%&gt;
  &lt;%@ page contentType="text/html;charset=UTF-8" %&gt;
  &lt;%@ include file="getcon.jsp"%&gt; &lt;!-- to connect a database--&gt;
  
  &lt;%
  try
  {
      String ImageFile="";
      String itemName = "";
      boolean isMultipart = ServletFileUpload.isMultipartContent(request);
      if (!isMultipart)
      {
      }
      else
      {
          FileItemFactory factory = new DiskFileItemFactory();
          ServletFileUpload upload = new ServletFileUpload(factory);
          List items = null;
          try
          {
              items = upload.parseRequest(request);
          }
          catch (FileUploadException e)
          {
              e.getMessage();
          }
  
          Iterator itr = items.iterator();
          while (itr.hasNext())
          {
              FileItem item = (FileItem) itr.next();
              if (item.isFormField())
              {
                  String name = item.getFieldName();
                  String value = item.getString();
                  if(name.equals("ImageFile"))
                  {
                      ImageFile=value;
                  }
              }
              else
              {
                  try
                  {
                      itemName = item.getName();
                      File savedFile = new File(config.getServletContext().getRealPath("/") + "Images\\" + itemName);
                      out.println("File Uploaded.." + itemName);
                      item.write(savedFile);
                  }
                  catch (Exception e)
                  {
                      out.println("Error" + e.getMessage());
                  }
              }
          }
          try
          {
              st.executeUpdate("insert into test(image) values ('" + itemName + "')");
          }
          catch(Exception el)
          {
              out.println("Inserting error" + el.getMessage());
          }
      }
  }
  catch (Exception e)
  {
      out.println(e.getMessage());
  }
  %&gt;
  </code></pre>
  
  <p><strong>This is my retrieveimage.jsp file</strong></p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;%@ include file="getcon.jsp"%&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;View Image Page&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;table width="100%" border="0"&gt;
  &lt;!-- main content --&gt;
  &lt;%
      ResultSet rs=null;
      try
      {
          rs = st.executeQuery("select image from test");
  
          while(rs.next())
          {
  %&gt;
          &lt;table width="70%" height="160" border="1" align="center"&gt;
              &lt;tr&gt;
                  &lt;!-- Mention Directory where your images has been saved--&gt;
                  &lt;td&gt;&lt;img src="Images/&lt;%=rs.getString("image") %&gt;" width="115" height="128" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
  &lt;%
          }
      }
      catch(Exception e)
      {
          out.print("" + e.getMessage());
      }
  %&gt;
          &lt;/table&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>This is my connection file</strong></p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;%@page import="java.sql.*" %&gt;
  
  &lt;%
  Class.forName("com.mysql.jdbc.Driver");
  Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/sample", "root", "root");
  Statement st = con.createStatement();
  %&gt;
  </code></pre>