title: java.lang.NumberFormatException: null error in doPost
body: <p>I'm creating a webpage that starts a list of vaccines. When I click on a link to edit a specific vaccine entry in the list, this is the webpage that users are brought to. The id parameter from that entry is passed to this page. Clicking on the save button calls doPost. when I try passing the id parameter from doGet into a new vaccineEntry object, the value for id turns up null.</p>
  <p>Here's the servlet code for list of vaccines:</p>
  <pre><code>package vaccineList.servlet;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.util.ArrayList;
  import java.util.List;
  
  import javax.servlet.ServletConfig;
  import javax.servlet.ServletException;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import NewVaccine.servlet.NewVaccine;
  import NewDose.servlet.NewDose;
  
  //import cs3220.model.GuestBookEntry;
  //import cs3220.utilities.*;
  
  @WebServlet(urlPatterns = &quot;/ListVaccine&quot;, loadOnStartup = 1)
  public class ListVaccine extends HttpServlet {
  
      private static final long serialVersionUID = 1L;
  
      public ListVaccine()
      {
          super();
      }
  
      public void init( ServletConfig config ) throws ServletException
      {
          super.init( config );
  
          List&lt;VaccineEntry&gt; entries = new ArrayList&lt;VaccineEntry&gt;();
          entries.add( new VaccineEntry( &quot;Pfizer/BioNTech&quot;, &quot;2&quot;, &quot;21&quot;, &quot;10000&quot;, &quot;10000&quot; ) );
          entries.add( new VaccineEntry( &quot;Johnson&amp;Johnson&quot;, &quot;1&quot;, &quot;0&quot;, &quot;5000&quot;, &quot;5000&quot;  ) );
  
          getServletContext().setAttribute( ServletFunctions.VaccineEntries, entries );
      }
  
      @SuppressWarnings(&quot;unchecked&quot;)
      protected void doGet( HttpServletRequest request,
          HttpServletResponse response ) throws ServletException, IOException
      {
          StringBuilder html = new StringBuilder();
          List&lt;VaccineEntry&gt; entries = ServletFunctions.getVaccineEntriesFromServletContext(getServletContext());
  
          response.setContentType( &quot;text/html&quot; );
          PrintWriter out = response.getWriter();
  
          html.append( &quot;&lt;p&gt;List Vaccine&lt;/p&gt;&quot; );
          
          html.append( &quot;&lt;p&gt;&lt;a href='NewVaccine'&gt;New Vaccine&lt;/a&gt; |&quot; );
          html.append( &quot;&lt;a href='NewDose'&gt; New Dose&lt;/a&gt;&lt;/p&gt;&quot; );
          
          html.append(&quot;&lt;table border='1'&gt;&quot;);
          
          html.append(&quot;&lt;tr&gt;&quot;);
          html.append( &quot;&lt;td&gt;   &quot; + &quot; &lt;b&gt;Vaccine&lt;/b&gt;   &lt;/td&gt;&quot; );
          html.append( &quot;&lt;td&gt;&quot; + &quot; &lt;b&gt;Doses Required&lt;/b&gt;&lt;/td&gt;&quot; );
          html.append( &quot;&lt;td&gt;&quot; + &quot; &lt;b&gt;Days Between Doses&lt;/b&gt;&lt;/td&gt;&quot; );
          html.append( &quot;&lt;td&gt;&quot; + &quot; &lt;b&gt;Total Doses Recieved&lt;/b&gt;&lt;/td&gt;&quot; );
          html.append( &quot;&lt;td&gt;&quot; + &quot; &lt;b&gt;Total Doses Left&lt;/b&gt;&lt;/td&gt;&quot; );
          html.append(&quot;&lt;td&gt;&lt;/td&gt;&quot; );
          html.append( &quot;&lt;/tr&gt;&quot; );
          
          for( VaccineEntry entry : entries )
          {
              
              html.append(&quot;&lt;tr&gt;&quot;);
              html.append( &quot;&lt;td&gt;&quot; + entry.getName() + &quot;&lt;/td&gt;&quot; );
              html.append( &quot;&lt;td&gt;&quot; + entry.getDosesReq() + &quot;&lt;/td&gt;&quot; );
              if(entry.getDaysBtwnDoses() == &quot;0&quot;) {
                  html.append( &quot;&lt;td&gt;&lt;/td&gt;&quot; );
              }
              else
                  html.append( &quot;&lt;td&gt;&quot; + entry.getDaysBtwnDoses() + &quot;&lt;/td&gt;&quot; );
              
              
              html.append( &quot;&lt;td&gt;&quot; + entry.getTotalDosesRecieved() + &quot;&lt;/td&gt;&quot; );
              html.append( &quot;&lt;td&gt;&quot; + entry.getTotalDosesLeft() + &quot;&lt;/td&gt;&quot; );
              
              
              html.append( &quot;&lt;td&gt;&lt;a href='editVaccine?id=&quot; + entry.getId() + &quot;'&gt;Edit&lt;/a&gt;&lt;/td&gt;&quot;  );
              
              
              html.append( &quot;&lt;/td&gt;&quot; );
              html.append( &quot;&lt;/tr&gt;&quot; );
          }
          html.append( &quot;&lt;/table&gt;&quot; );
          
          
          
          out.println( ServletFunctions.titleWithBody(&quot;ListVaccine&quot;, html.toString()) );
      }
  
  }
  </code></pre>
  <p>and here's the code for the editVaccine page:</p>
  <pre><code>package EditVaccine.servlet;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.util.List;
  
  import javax.servlet.ServletException;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  
  import vaccineList.servlet.*;
  
  
  @WebServlet(&quot;/editVaccine&quot;)
  public class editVaccine extends HttpServlet {
      private static final long serialVersionUID = 1L;
         
      
      public editVaccine() {
          super();
          
      }
      
      @SuppressWarnings(&quot;unchecked&quot;)
      private VaccineEntry getEntry( int id )
      {
          List&lt;VaccineEntry&gt; entries = (List&lt;VaccineEntry&gt;) getServletContext()
              .getAttribute( &quot;entries&quot; );
          System.out.println(&quot;entry taken is &quot; + id);
          
          
          for( VaccineEntry entry : entries )
              if( entry.getId() == id ) return entry;
          return null;
      }
  
      
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          
          StringBuilder html = new StringBuilder();
          
          String id = request.getParameter( &quot;id&quot; );
          VaccineEntry entry = getEntry(Integer.parseInt(id));
          System.out.println(&quot;The value of id is &quot; + id);
          
          
          System.out.println(&quot;The value of getEntry is &quot; + entry.getId());
  
          response.setContentType( &quot;text/html&quot; );
          PrintWriter out = response.getWriter();
          
          html.append(&quot;&lt;form action='editVaccine' method='post'&gt;&quot; );
          html.append(&quot;&lt;table border='1' cellpadding='2'&gt;&quot;);
          html.append(&quot;&lt;tr&gt;&quot; + &quot;&lt;th colspan='2'&gt;Name&lt;/th&gt;&quot;);
          html.append(&quot;&lt;td&gt;&lt;input type='text' name='name' value=&quot; + entry.getName() + &quot;&gt;&lt;/input&gt;&lt;/td&gt;&quot; + &quot;&lt;/tr&gt;&quot;);
          html.append(&quot;&lt;tr&gt;&lt;th colspan='2'&gt;Doses Required&lt;/th&gt;&quot; + &quot;&lt;td&gt;&lt;select name='DosesReq' value='&quot; + entry.getDosesReq() + &quot;'&gt;&quot;); // id='Doses Required'
          html.append(&quot;&lt;option value='1' name='dosage' value='&quot; + entry.getDosesReq() + &quot;'&gt;1&lt;/option&gt;&quot;);
          html.append(&quot;&lt;option value='2' name='dosage' value='&quot; + entry.getDosesReq() + &quot;'&gt;2&lt;/option&gt;&quot;);
          html.append(&quot;&lt;option value='3' name='dosage' value='&quot; + entry.getDosesReq() + &quot;'&gt;3&lt;/option&gt;&quot;);
          html.append(&quot;&lt;/select&gt;&lt;/td&gt;&quot;);
          html.append(&quot;&lt;tr&gt;&lt;th colspan='2'&gt;Days Between Doses&lt;/th&gt;&lt;td&gt;&lt;input type='text' name= 'DaysBtwnDoses' value='&quot; + entry.getDaysBtwnDoses() + &quot;'&gt; &lt;/input&gt;&lt;/td&gt;&lt;/tr&gt;&quot;);
          html.append(&quot;&lt;td colspan = '2'&gt;&lt;button&gt;Save&lt;/button&gt;&lt;/td&gt;&quot;);
          html.append(&quot;&lt;/form&gt;&quot;);
          html.append(&quot;&lt;/table&gt;&quot;);
          
          
          out.println( ServletFunctions.titleWithBody(&quot;ListVaccine&quot;, html.toString()) );
          
         
          
      }
  
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          System.out.println(&quot;In post method&quot;);
          
          VaccineEntry entry = getEntry(Integer.parseInt(request.getParameter(&quot;id&quot;)));
          
          entry.setName(request.getParameter(&quot;name&quot;));
          String name = entry.getName();
          System.out.println(&quot;name is &quot; + name);
          entry.setDosesReq(request.getParameter(&quot;dosage&quot;));
          String dosage = entry.getDosesReq();
          System.out.println(&quot;dosage is &quot; + dosage);
          entry.setDaysBtwnDoses(request.getParameter(&quot;DaysBtwnDoses&quot;));
          String DaysBtwnDoses = entry.getDaysBtwnDoses();
          System.out.println(&quot;DaysBtwnDoses is &quot; + DaysBtwnDoses);
          
          response.sendRedirect(&quot;ListVaccine&quot;);
          return;
          
      }
  
  }
  </code></pre>