先看以下这段代码:     
 <td><html:select property="studentID" styleClass="word" >
        <html:option value="">select</html:option>
        <html:optionsCollection name="studentForm" property="studentList" styleClass="word" />
      </html:select></td>例如html:optionsCollection从数据库获取的记录有三条:
  label="zhangsan" value="1"
  label="lisi" value="2"
  label="wangwu" value="3"
每次打开网页时,此下拉框都会显示第一项的内容"select",请问我如何才能让它显示数据库里保存的某一项的值?
辟如我数据库中studentID的值为2,就让它显示"lisi".

解决方案 »

  1.   

    <html:select property="studentID" styleClass="word" >给一个默认值,而默认值的值就是数据库选出来的那个值!
      

  2.   

    楼上所说的就是我想要的,可我对JSP的语法不熟,不知道怎么给它默放值呀.我知道可以在html:option给他默认值,可我不知道如何将STUDENTID给它呀.可否提示一下?
      

  3.   

    optionsCollection 这个集合有自动匹配的功能阿
    你给property一个值,他会自动根据id把label找出来
      

  4.   

    给你的form表单对应的bean的属性studentID赋上初始值,在bean的reset()方法里给其赋值
    reset(){
      this.studentID="1";
    }