title: Using a Servlet doPost method
body: <p>Im new to Java and trying out some financial analysis java file I'm using for my studies. I got it to work when I created a main method within the bean itself. However when I try to pass the values needed through a jsp form and using a servlet doPost method to do the calculations by instantiating the methods from the bean nothing happens I get a NullPointerException. Im assuming the BlackScholes.java works as a bean should and that the issue is within the code presented. Help here would be greatly appreciated.</p>
  
  <pre><code>protected void doPost(HttpServletRequest request,
          HttpServletResponse response) throws ServletException,IOException   {
  
      String action = request.getParameter("action");
  
      if (action != null) {
          try {
              String spotPrice = request.getParameter("sprice");
              String strikePrice = request.getParameter("strike");
              String interestRate = request.getParameter("rate");
              String timeTo = request.getParameter("time");
              String vol = request.getParameter("volatility");
  
              double sprice = Double.parseDouble(spotPrice);
              double strike = Double.parseDouble(strikePrice);
              double rate = Double.parseDouble(interestRate);
              double time = Double.parseDouble(timeTo);
              double volatility = Double.parseDouble(vol);
              double carryrate = rate;
  
              request.setAttribute("sprice", sprice);
              request.setAttribute("strike", strike);
              request.setAttribute("rate", rate);
              request.setAttribute("time", time);
              request.setAttribute("volatility", volatility);
  
              BlackScholes BS = new BlackScholes(carryrate);
              BS.bscholEprice(sprice, strike, volatility, time, rate);
              double currentpriceC = BS.getCalle();
              request.setAttribute("validation1", currentpriceC);
          } catch (NullPointerException e) {
              return;
          }
      } else {
          request.getRequestDispatcher("/index.jsp").forward(request,
                  response);
      }
    }
  }
  </code></pre>
  
  <p>The jsp file used to creat the form data:</p>
  
  <pre><code>&lt;form action="${pageContext.request.contextPath}/OptionsController"
      method="post"&gt;
      &lt;input type="hidden" name="action" value="docalculate" /&gt; 
  
      Spot Price: &lt;input type="text" name="sprice" /&gt; &lt;br /&gt;
      &lt;p /&gt;
      Strike Price: &lt;input type="text" name="strike" /&gt; &lt;br /&gt;
      &lt;p /&gt;
      Risk Free Rate: &lt;input type="text" name="rate" /&gt; &lt;br /&gt;
      &lt;p /&gt;
      Months To Expire: &lt;input type="text" name="time" /&gt; &lt;br /&gt;
      &lt;p /&gt;
      Volatility: &lt;input type="text" name="volatility" /&gt; &lt;br /&gt;
      &lt;p /&gt;
  
      &lt;input type="submit" value="Submit" /&gt;&lt;br /&gt;
      &lt;p /&gt;
      One call options costs: &lt;input type="text" name="validation1"
          readonly="readonly"
          value="&lt;%if (request.getAttribute("validation1") != null) {
              out.print(request.getAttribute("validation1"));
          }%&gt;"&gt;
  &lt;/form&gt;
  </code></pre>