title: How to resolve req.getParameter() returning null in servlet?
body: <p>I am reading 2 numbers as input and am trying to print them in the output dynamically using Servlet, req.getParameter() returns null:</p>
  <blockquote>
  <p>HTTP Status 500 – Internal Server Error Type Exception Report</p>
  <p>Message null</p>
  <p>Description The server encountered an unexpected condition that
  prevented it from fulfilling the request.</p>
  <p>Exception</p>
  <p>java.lang.NumberFormatException: null   java.lang.Integer.parseInt(Integer.java:542)
  java.lang.Integer.parseInt(Integer.java:615)
  com.telusko.AddServlet.service(AddServlet.java:11)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
  org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
  Note The full stack trace of the root cause is available in the server
  logs.</p>
  </blockquote>
  <p>Apache Tomcat/9.0.26</p>
  <p>Index.html</p>
  <pre><code>    &lt;!DOCTYPE html&gt;
      &lt;html&gt;
        &lt;head&gt;
          &lt;meta charset=&quot;ISO-8859-1&quot;&gt;
          &lt;title&gt;Insert title here&lt;/title&gt;
        &lt;/head&gt;
        &lt;body&gt;
           &lt;form action=&quot;add&quot;&gt;
              Enter 1st number: &lt;input type=&quot;text' name=&quot;num1&quot;&gt;&lt;br&gt;
              Enter 2nd number: &lt;input type=&quot;text' name=&quot;num2&quot;&gt;&lt;br&gt;
              &lt;input type=&quot;submit&quot;&gt;
           &lt;/form&gt;
        &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  <p>AddServlet.java</p>
  <pre><code>  package com.telusko;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
  
    public class AddServlet extends HttpServlet
   {
  public void service(HttpServletRequest req, HttpServletResponse res)
  {
      int i =Integer.parseInt(req.getParameter(&quot;num1&quot;));
      int j =Integer.parseInt(req.getParameter(&quot;num2&quot;));
      int k = i + j;
      System.out.println(&quot;result is&quot;+k);
  }
    }
  </code></pre>
  <p>Web.xml</p>
  <pre><code>    &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
      &lt;web-app xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; 
         xmlns=&quot;http://xmlns.jcp.org/xml/ns/javaee&quot; 
         xsi:schemaLocation=&quot;http://xmlns.jcp.org/xml/ns/javaee 
         http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd&quot; id=&quot;WebApp_ID&quot; 
         version=&quot;3.1&quot;&gt;
   &lt;servlet&gt;
       &lt;servlet-name&gt;abc&lt;/servlet-name&gt;
      &lt;servlet-class&gt;com.telusko.AddServlet&lt;/servlet-class&gt;
  &lt;/servlet&gt;
  
  &lt;servlet-mapping&gt;
       &lt;servlet-name&gt;abc&lt;/servlet-name&gt;
       &lt;url-pattern&gt;/add&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>I know that my result will get printed in my eclipse console.</p>