在struts1的action里想获得 jsp页面上radio里选的值 
插入到数据库中 
属性是sex(性别)类型String 界面上该怎么定义 <td>性别</td> 
        <td> 
            <input name="connectorType" type="radio" value="1"/>亲人
            <input name="connectorType" type="radio" value="2"/>朋友
            <input name="connectorType" type="radio" value="3"/>同事 
        </td> Action中该怎么写 语句???? 一、是先用javascript在页面上获取radio的value值,然后设置一个变量保存,再在action里获取这个变量吗?二、还是直接在action里面写如下代码:
             DynaValidatorForm addStudentForm = (DynaValidatorForm)form;
    String connectorType =null;
String radio = (String) addStudentForm.get("connectorType");
if(radio=="1")
connectorType ="Relative";
if(radio=="2")
    connectorType ="Friend";
if(radio=="3")
    connectorType ="Colleague";
但是第二种方法不可行啊???怎么办???

解决方案 »

  1.   

    你在action中添加一个 connectorType  的set和get方法  然后就可以得到  connectorType  的值为1或2或3建议lz看看struts的书籍……基础打牢
      

  2.   

    不行啊,这种方法试过了啊 我打印String radio = (String) addStudentForm.get("connectorType");中的radio的值,根本就没有输出
      

  3.   

    String radio = request.getparameter("connectorType");
      这句话已经获取到你的radio值了
    至于后面的判断就不要了,前台jsp中radio会有一个默认的check=checked,被选中的radio就会被传到action中
      

  4.   

    不行啊!!!怎么会这样子!!我打印String radio = (String) addStudentForm.get("connectorType");中的radio的值,根本就没有输出
      

  5.   

    String radio = request.getparameter("connectorType");
    String radio = (String) addStudentForm.get("connectorType");
     先看清楚了再说
      

  6.   

    还是没有获取到!是不是要使用struts标签库 html:radio?
      

  7.   

    <html:radio property="connectorType" value="1" ></html:radio>
    <html:radio property="connectorType" value="2" ></html:radio>
    <html:radio property="connectorType" value="3" ></html:radio>
    你自己试下
      

  8.   

    ....有FORM不会用啊StudentForm studentForm = (StudentForm)form;  
                          String stuSex = studentForm.getStudentSex();
                          StudentForm 中有这个属性studentSex,且在页面上绑定。
      

  9.   

    我没有StudentForm,我用的是DynaValidatorForm