title: Need help on passing data from jsp to servlet
body: <p>Im currently new in java ee. I need help on how to pass my data from jsp to my servlet to fil up my query. Whenever i run, the error is being catch and i print out the exception. It says java.null.exception.. I couldn't find out where my error is..pls help me... thanks..</p>
  
  <p>Here is my code: </p>
  
  <p>UpdateProductServlet.java</p>
  
  <pre><code>    try {
          String description = request.getParameter("description");
          float price = Float.parseFloat(request.getParameter("price"));
          String size = request.getParameter("size");
          int aisle_id = Integer.parseInt(request.getParameter("aisle"));
          int id = Integer.parseInt(request.getParameter("id"));
  
          ProductsDao productsDao = new ProductsDao();
          productsDao.updateProduct(description, price, size, aisle_id, id);
  
      } catch (Exception e) {
          out.println(e);
      }
  </code></pre>
  
  <p>and my ProductDao.java</p>
  
  <pre><code>public void updateProduct(String description, float price, String size, int aisle_id, int id) 
          throws ClassNotFoundException, SQLException {
      Connection conn = null;
      PreparedStatement stmt = null;
      String sql = "UPDATE products "
              + "SET description = ?, price = ?, size = ?, aisle_id = ? "
              + "WHERE id = ? ";
  
      try {
          conn = ConnectionFactory.getConnection();
          stmt = conn.prepareStatement(sql);
          stmt.setString(1, description);
          stmt.setFloat(2, price);
          stmt.setString(3, size);
          stmt.setInt(4, aisle_id);
          stmt.setInt(5, id);
          stmt.executeUpdate();
  
      } finally {
          if (conn != null) {
              conn.close();
          }
  
          if (stmt != null){
              stmt.close();
          }
      }
  }
  </code></pre>
  
  <p>and this is my ProductById.jsp</p>
  
  <pre><code>&lt;%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %&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;script&gt;
          function functionEdit()
          {
              document.getElementById("edit").type="hidden";
              document.getElementById("update").type="button";
              document.getElementById("delete").type="hidden";
              document.getElementById("cancel").type="button";
  
              document.getElementById("description").disabled="";
              document.getElementById("size").disabled="";
              document.getElementById("price").disabled="";
              document.getElementById("select").disabled="";
          }
  
          function functionUpdateRecord(){
              if(confirm('Update existing record?')){
                  document.location.href="/MachineProblemWebApp/UpdateProductServlet";
                  alert('Update success!');
                  document.location.href="/MachineProblemWebApp/GetAllProductsServlet";
  
              }else{ 
                  alert('No changes have been made!');
              }
  
          }
  
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;table border="0"&gt;
          &lt;tr&gt;
              &lt;td&gt;id: &lt;/td&gt;
              &lt;td&gt;&lt;input type="text" name="id" id="id" value="${product.id}" disabled="disabled"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Description: &lt;/td&gt;
              &lt;td&gt;&lt;input type="text" name="description" id="description" value="${product.description}" disabled="disabled"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Aisle &lt;/td&gt;
              &lt;td&gt;&lt;select name="aisle" disabled="disabled" id="select"&gt;
                      &lt;c:forEach var="aisle" items="${aisles}" &gt;
                          &lt;option value="${aisle.id}" ${(aisle.id==product.aisle.id)?"selected" : ""}&gt;${aisle.description}&lt;/option&gt;
                      &lt;/c:forEach&gt;
                  &lt;/select&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Size: &lt;/td&gt;
              &lt;td&gt;&lt;input type="text" name="size" id="size" value="${product.size}" disabled="disabled"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Price: &lt;/td&gt;
              &lt;td&gt;&lt;input type="text" name="price" id="price" value="${product.price}" disabled="disabled"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;input type="button" name="edit" id="edit" onClick="functionEdit()" value="Edit" &gt;
                  &lt;input type="hidden" name="update" id="update" onClick="functionUpdateRecord()"value="Update"&gt;
                  &lt;input type="button" name="delete" id="delete" value="Delete"&gt;
                  &lt;input type="hidden" name="cancel" id="cancel" value="Cancel"&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  
  &lt;/body&gt;
  </code></pre>
  
  <p></p>
  
  <p>is this the stack trace? posted in Apache Tomcat Log?</p>
  
  <pre><code>Dec 10, 2012 7:38:13 PM org.apache.catalina.core.StandardWrapperValve invoke
  SEVERE: Servlet.service() for servlet [UpdateProductServlet] in context with path     [/MachineProblemWebApp] threw exception
  java.lang.NullPointerException
  at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1008)
  at java.lang.Float.parseFloat(Float.java:452)
  at grocerific.ui.UpdateProductServlet.processRequest(UpdateProductServlet.java:45)
  at grocerific.ui.UpdateProductServlet.doGet(UpdateProductServlet.java:75)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
  at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
  at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
  at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
  at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
  at java.lang.Thread.run(Thread.java:722)
  
  Dec 10, 2012 9:36:40 PM org.apache.catalina.core.ApplicationContext log
  INFO: SessionListener: contextDestroyed()
  Dec 10, 2012 9:36:40 PM org.apache.catalina.core.ApplicationContext log
  INFO: ContextListener: contextDestroyed()
  Dec 10, 2012 9:36:46 PM org.apache.catalina.core.ApplicationContext log
  INFO: ContextListener: contextInitialized()
  Dec 10, 2012 9:36:46 PM org.apache.catalina.core.ApplicationContext log
  INFO: SessionListener: contextInitialized()
  Dec 10, 2012 9:36:46 PM org.apache.catalina.core.ApplicationContext log
  INFO: ContextListener: attributeAdded('org.apache.jasper.compiler.TldLocationsCache', 'org.apache.jasper.compiler.TldLocationsCache@8a47d9')
  </code></pre>