0

home.jsp

        <form method="POST" action="Initiater.do">
    <table>
      <tr>
          <td>
           Internal Diameter from FlowAss:
          </td>
           <td>
           <input type="text" id="Id" />
          </td>
          <td>
            Depth:
            </td>
             <td>
  <input type="text" id="Depth" />
            </td>
             <td>
           Units:
            </td>
             <td>
         <select>
         <option value="ft">feet</option>
         <option value="mts">meters</option>
          </select>
            </td>
            </tr>
             <tr>
             <td>
          <input type="submit" />
      </td>
       </tr>
    </table>
       </form>
         </body>
             </html>

Home.java public class Home extends HttpServlet {

public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException
{
    System.out.println("in Post");
    String id = (String) request.getParameter("Id");
    String depth = request.getParameter("Depth");
    /*double id =Double.parseDouble(request.getParameter("Id"));
    double depth =Double.parseDouble(request.getParameter("Depth"));*/
    System.out.println("Id"+id);
    System.out.println("Depth"+depth);
}

the servlet Home.java's doPost method is called, the values id and depth are returning nulls when I debug can anyone help me out with this.

1 Answers1

2

Add name attribute to the input tag.

Change

  <input type="text" id="Depth" />
  <input type="text" id="Id" />

To

  <input type="text" id="Depth" name="Depth"/>
  <input type="text" id="Id" name="Id"/>

Request.getParameter gets data by name attribute and not id

Sanj
  • 3,879
  • 2
  • 23
  • 26