title: FileNotFoundException web.xml
body: <p>continuing my studies... I'm trying to write some data into a txt file but I'm receiving this exception. I'm using Tomcat 7.0. The EmailList.txt is in the folder, so I don't know what is going one. Can you guys please, help me</p>
  
  <p><strong>web.xml</strong> </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;AddToEmailListServlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;email.AddToEmailListServlet&lt;/servlet-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;relativePathToFile&lt;/param-name&gt;
              &lt;param-value&gt;/WEB-INF/EmailList.txt&lt;/param-value&gt;
          &lt;/init-param&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;AddToEmailListServlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/addToEmailList&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
      &lt;session-config&gt;
          &lt;session-timeout&gt;30&lt;/session-timeout&gt;
      &lt;/session-config&gt;
      &lt;welcome-file-list&gt;
          &lt;welcome-file&gt;join_email_list.jsp&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p><strong>servlet class</strong> This class is going to process the data.</p>
  
  <pre><code>package email;
  
  import java.io.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  import business.User;
  import data.UserIO;
  
  public class AddToEmailListServlet extends HttpServlet
  {   @Override 
      protected void doPost(HttpServletRequest request, 
                            HttpServletResponse response) 
                            throws ServletException, IOException
      {
          // get parameters from the request
          String firstName = request.getParameter("firstName");
          String lastName = request.getParameter("lastName");
          String emailAddress = request.getParameter("emailAddress");
  
          User user = new User(firstName, lastName, emailAddress);
  
         //validation
          String message = "";
          String url = "";
          if (firstName.length() == 0 || lastName.length() == 0 || emailAddress.length() == 0) {
              message = "Please fill out all three boxes";
              url = "/join_email_list.jsp";
          }else{
              message = "";
              ServletConfig config = getServletConfig();
              String relativePath = config.getInitParameter("relativePathToFile");
              UserIO.addRecord(user, relativePath);
              url = "/display_email_entry.jsp";
          }
          request.setAttribute("user", user);
          request.setAttribute("message", message);
  
          //forward request and response
  
          RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
          dispatcher.forward(request, response);             
      }    
  }
  </code></pre>
  
  <p>The I/O class</p>
  
  <p>package data;</p>
  
  <p>import java.io.<em>;
  import java.util.</em>;</p>
  
  <pre><code>import business.User;
  
  public class UserIO
  {
      public static void addRecord(User user, String filename) throws IOException
      {
          File file = new File(filename);
          PrintWriter out = new PrintWriter(
                  new BufferedWriter(new FileWriter(file)));
          out.println(user.getEmailAddress()+ "|"
                  + user.getFirstName() + "|"
                  + user.getLastName());        
          out.close();
      }
  }
  </code></pre>