基本的request.getParameter无效

时间:2016-04-05 20:44:22

标签: java jsp servlets

针对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扩展了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);
}

调用servlet Home.java的doPost方法,当我调试时,值id和depth返回null,任何人都可以帮我解决这个问题。

1 个答案:

答案 0 :(得分:2)

将name属性添加到输入标记。

更改

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

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

Request.getParametername属性获取数据,而不是id