title: Servlet java.lang.NumberFormatException
body: <p>I'm receiving two parameters on the servlet that I need to put as string so that in the <code>PreparedStatement</code> I can use <code>setInt(1, parameter)</code>.</p>
  
  <pre><code>public class rate extends HttpServlet {
  
      @Override
      protected void doPost(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException
      {
          response.setContentType("text/html;charset=UTF-8");
          PreparedStatement pstmt = null;
          Connection con = null;
         //FileItem f1;
          String id = request.getParameter("idbook");
          String opcoes = request.getParameter("voto");
          int idlivro=Integer.parseInt(id);
          int opcao = Integer.parseInt(opcoes);
          String updateString = "Update rating set livros_rate = ? where productId = ?";
          if (idlivro != 0)
       {
  
            try {
           //connect to DB 
           con = login.ConnectionManager.getConnection();
           pstmt = con.prepareStatement(updateString);
           pstmt.setInt(1, opcao);
           pstmt.setInt(2, idlivro);
           pstmt.executeUpdate();
        }
            catch (Exception e){
        }finally{
               try {
                   pstmt.close();
                   con.close();
               } catch (SQLException ex) {
                   Logger.getLogger(rate.class.getName()).log(Level.SEVERE, null, ex);
               }
  
            }
       }
  }
  </code></pre>
  
  <p>However, it throws the following exception:</p>
  
  <pre><code>java.lang.NumberFormatException: null
      at java.lang.Integer.parseInt(Integer.java:454)
      at java.lang.Integer.parseInt(Integer.java:527)
      at counter.rate.doPost(rate.java:45)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:728
  </code></pre>
  
  <p>How is this caused and how can I solve it?</p>
  
  <p>Edit: I'll put the code of the form that send's the parameters.</p>
  
  <pre><code>&lt;div id="templatemo_content_right"&gt;
      &lt;div class="templatemo_product_box"&gt;
              &lt;h1&gt;&lt;%=rs.getString(3)%&gt;  &lt;span&gt;(&lt;%=rs.getString(7)%&gt;)&lt;/span&gt;&lt;/h1&gt;
          &lt;img src="&lt;%=rs.getString(13)%&gt;"/&gt;
              &lt;div class="product_info"&gt;
                  &lt;p&gt;&lt;%=rs.getString(10)%&gt;&lt;/p&gt;
                     &lt;div&gt;&lt;form action="rate"  method="POST"&gt;
                              &lt;imput type="hidden" name="idbook" value="&lt;%=rs.getString(1)%&gt;"/&gt;
                              &lt;select name="voto"&gt;
                                  &lt;option value="0"&gt;Did not like&lt;/option&gt;
                                  &lt;option value="1"&gt;Ok&lt;/option&gt;
                                  &lt;option value="2" selected="selected"&gt;Liked&lt;/option&gt;
                                  &lt;option value="3"&gt;Loved!&lt;/option&gt;
                              &lt;/select&gt;
                              &lt;input type="submit" value="Votar!"/&gt;
                      &lt;/form&gt;&lt;/div&gt;
  </code></pre>
  
  <p>is the form causing the problem?</p>