主要代码:jsp
...
<input type = "radiio",name = "type" value = "1">消费者</input>
<input type = "radio",name = "type" value = "2">卖家</input>
...action:...
private String type;get,set方法略去。
/*
想拿到radio中选中的选项的value,转为int
*/
int type_int = Integer.parseInt(type);

可以么?
这样的话会报错之前我用的是这样
private int type;
 get set方法略去直接使用type作为对应的value的值这样的话type总是0.。。各位大侠们求助哈  有点蒙现在。下面是在百度的回答:radio的值需是checked为true时的值<input type = "radiio",name = "type" value = "1" check="checked">消费者</input>
<input type = "radio",name = "type" value = "2">卖家</input>此时type的值为1get set会自动转型,所以不用你操作 追问不行啊 type拿到的不管我选中那个,总是0.。。咋办?现在的jsp:
...
<input type = "radiio",name = "type" value = "1" check="checked">消费者</input>
<input type = "radio",name = "type" value = "2">卖家</input>
...
action :
private int type;
get set 方法
System.out.println(type);结果总是0.。为什么呢?    回答<input type = "radio",name = "type" value = "1" check="checked">消费者</input>
<input type = "radio",name = "type" value = "2">卖家</input>你需要把input元素放在表单里才可以    追问放在表单里了 纠结死我了,怎么会总是0呢,是我用的方法不对? 不能直接使用type么? 打印type时会自动转成int?
奇怪为什么会是0呢?
改成string就是null,选中之后没有效果?    
还是没有解决,csdn的各位大侠们,有什么好的建议么。。

解决方案 »

  1.   

    <input type = "radiio",name = "type" value = "1" check="checked">这句有两个问题,绝色标记改为<input type = "radio" name = "type" value = "1" check="checked">试试
    特别是那个逗号,看不懂。估计浏览器也看不懂。你可以试试把表单的method的方法改为method="get";看跳转后的URL中的type的值是什么。
      

  2.   

    <input type = "radiio",name = "type" value = "1">多个i还多个逗号
    另外一个radio也多个逗号
    估计Html页面根本就没解析成功
      

  3.   

    楼上说对了,自己不细心
    你也可以这样子,在逻辑代码中判断
    int IsCheck=0;//默认给个值
    if(radio.checked==true){
      IsCheck=0;
    }else{
       IsCheck=1;
    }