【问题标题】:Get checked Radio Button Value from JSP to Servlet获取从 JSP 到 Servlet 的选中单选按钮值
【发布时间】:2014-12-26 20:39:59
【问题描述】:

在 HTML/JSP 中,

<input type="radio" value="10" name="a">10 Records
<input type="radio" value="20" name="a">20 Records
<input type="radio" value="50" name="a">50 Records 

在 Servlet 中,

String val= request.getParameter("a");
System.out.println("Record is : "+val);

变量val 返回null

【问题讨论】:

  • 你确定你提交的时候选择了一个吗?
  • 你是怎么发的?
  • 是的,它是我提交时选择的一个

标签: jsp servlets


【解决方案1】:

希望你有类似的代码,然后它会给你a的值

<form action="/Servlet" method="post">
     <input type="radio" value="10" name="a">10 Records
     <input type="radio" value="20" name="a">20 Records
     <input type="radio" value="50" name="a">50 Records 
    // submit button here
</form>

【讨论】:

    【解决方案2】:

    检查您的表单是否指定了方法 post。请参考下面

    <form action="/Servlet" method="post">
         <input type="radio" value="10" name="a">10 Records
         <input type="radio" value="20" name="a">20 Records
         <input type="radio" value="50" name="a">50 Records 
         <input type = "submit" value = "submit"/>
    </form>
    

    那么它应该可以工作。

    【讨论】:

      【解决方案3】:

      我面临同样的问题。我试试这个,效果很好。

      <input type="radio" value="10" name="a">10 Records **</input>**
      <input type="radio" value="20" name="a">20 Records **</input>**
      <input type="radio" value="50" name="a">50 Records **</input>**
      

      【讨论】:

        猜你喜欢
        • 2019-08-14
        • 2015-05-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-03-24
        • 2015-12-22
        相关资源
        最近更新 更多