title: Why does servlet throw FileNotFoundException, while standalone application works?
body: <p>I am trying to open an Excel file using Apache POI in a servlet.</p>
  
  <p>I have already tested this in a basic java application, where it works, but in the servlet, I'm getting:</p>
  
  <pre class="lang-none prettyprint-override"><code>java.io.FileNotFoundException
  </code></pre>
  
  <p>Here is  my <code>index.html</code>:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;center&gt;
  &lt;h2&gt;
  &lt;a href="ExcelSrv"&gt;Click Here&lt;/a&gt;
  &lt;/h2&gt;
  &lt;/center&gt;
  </code></pre>
  
  <p>ExcelGenerator.java:</p>
  
  <pre><code>package com.nody;
  
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.util.Iterator;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import org.apache.poi.ss.usermodel.Cell;
  import org.apache.poi.ss.usermodel.Row;
  import org.apache.poi.xssf.usermodel.XSSFSheet;
  import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  
  
  public class ExcelGenerator extends HttpServlet {
  private static final long serialVersionUID = 1L;
  public ExcelGenerator() 
  {}
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
  {
  response.setContentType("text/html");
  PrintWriter out=response.getWriter();
  try
  {
  FileInputStream file = new FileInputStream(new File("WebContent/files/source.xlsx"));       //Create Workbook instance holding reference to .xlsx file
  XSSFWorkbook workbook = new XSSFWorkbook(file);
  //Get first/desired sheet from the workbook
  XSSFSheet sheet = workbook.getSheetAt(0);
  //Iterate through each rows one by one
  Iterator&lt;Row&gt; rowIterator = sheet.iterator();
   while (rowIterator.hasNext())
     {                        
      Row row = rowIterator.next();
      //For each row, iterate through all the columns
      Iterator&lt;Cell&gt; cellIterator = row.cellIterator();
    while (cellIterator.hasNext())
       {
        Cell cell = cellIterator.next();
        //Check the cell type and format accordingly
        switch (cell.getCellType())
         {
          case Cell.CELL_TYPE_NUMERIC:
          System.out.print(cell.getNumericCellValue() + "");
          break;
          case Cell.CELL_TYPE_STRING:
          System.out.print(cell.getStringCellValue() + "");
          break;
         }
       }
      System.out.println("");
     }
    file.close();
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
   }
  }
  </code></pre>
  
  <p>web.xml:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"&gt;
    &lt;display-name&gt;ExcelGenerator&lt;/display-name&gt;
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
      &lt;welcome-file&gt;index.htm&lt;/welcome-file&gt;
      &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.html&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.htm&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.jsp&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
    &lt;servlet&gt;
      &lt;description&gt;&lt;/description&gt;
      &lt;display-name&gt;ExcelGenerator&lt;/display-name&gt;
      &lt;servlet-name&gt;ExcelGenerator&lt;/servlet-name&gt;
      &lt;servlet-class&gt;com.nody.ExcelGenerator&lt;/servlet-class&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;ExcelGenerator&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/ExcelSrv&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>My Jar files:</p>
  
  <pre class="lang-none prettyprint-override"><code>dom4j-1.6.1.jar
  poi-3.12-beta1-20150228.jar
  poi-ooxml-3.12-beta1-20150228.jar
  poi-ooxml-schemas-3.12-beta1-20150228.jar
  servlet-api.jar
  xmlbeans-2.6.0.jar
  </code></pre>
  
  <p>I kept my Excel file in <code>WebContent/files/source.xlsx</code>, and it contains only one column.</p>