我刚做了一个同样的 <select name="">
    if (xb="男")
      out.print("<option value='"+xb+"' selected">+xb+"</option>")
    else
      out.print("<option value='"+xb+"'">+xb+"</option>"
 </select>
大概是这个意思

解决方案 »

  1.   

    to :RayZ(风) ,性别是从数据库读取的,而起是用Struts实现,不是JSPto VVV_lucky(*太阳*) ,能说具体点吗???
      

  2.   

    在页面上:
    <html:select property="sex">
        <html:options collection="dbList" property="id" labelProperty="name"/>
    </html:select>
    说明:
    dbList是一个ArrayList,里面是一个个的性别对象,要有getId()和getName()的方法
    labelProperty是在页面显示的数据,例如“男/女”,id是显示数据的代表值,0/1等在你的Action:
    把数据库里面的数据取出来,放到dbList里面去就这样,就OK。要是嫌麻烦,就把name和id弄成一个。
      

  3.   

    补充一下:
    如果不想区分name和id
    那就不用写labelProperty属性了。
      

  4.   

    to :RayZ(风) ,性别是从数据库读取的,而起是用Struts实现,不是JSP这跟是什么没关系吧?
      

  5.   

    <html:select property="sex">
        <html:options collection="dbList" property="id" labelProperty="name"/>
    </html:select>
    这个应该就可以
    你也可以加个循环,判断一下,但不是纯MVC了
      

  6.   

    应该是一样的吧,你可以用<logic:iterate>呀,里面嵌套<logic:equal>
    不过我struts不熟,option怎么办还没想好怎么处理
      

  7.   

    你们都没有回答我的问题啊,我就是想知道怎么用Struts判断是男是女
      

  8.   

    页面上这么写:
    <html:select property="sex">
        <html:options collection="dbList" property="id" labelProperty="name"/>
    </html:select>
    Action里面:
    把你从数据库里取出来的数据放到sex这个field里面去。
    至于页面上要用到的这个dbList,你怎么都行,可以放到form里。
    dbList里的值是死的,ArrayList里面放两个LabelBean对象。
    LabelBean里面有getId()和getName()就行了。页面显示的时候,从数据库里取到的值就是选中状态!Struts在解释html:options 这个标签的时候,预先取到sex这个值,在render HTML的option的时候,从collection里面取到一条纪录LabelBean,调用LabelBean的getId()和getName()
    <option value="getId()">getName()</option>
    在页面显示的时候,如果collection中某个LabelBean的getId()个sex的值相等的话,这个option的selected就等于selected。这个LabelBean是我随便叫得,随便是什么都行。
      

  9.   

    while(rs.next()){
       String m=rs.getString("m");
    %><option value=<%=m%> <%if(m.equals("男"))out.print(" selected");%>>
    <%
    }