【问题标题】:Basic request.getParameter not working [duplicate]基本 request.getParameter 不起作用[重复]
【发布时间】:2016-04-05 20:44:22
【问题描述】:

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 公共类 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 在我调试时返回空值,谁能帮我解决这个问题。

【问题讨论】:

    标签: java jsp servlets


    【解决方案1】:

    为输入标签添加名称属性。

    改变

      <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.getParameter 通过name 属性而不是id 获取数据

    【讨论】:

    • hi sanj 感谢您的回复,这很有效...
    猜你喜欢
    • 1970-01-01
    • 2011-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-30
    • 1970-01-01
    • 1970-01-01
    • 2019-04-06
    相关资源
    最近更新 更多