在下拉列表中启用整个数据库列作为选项

时间:2014-01-18 15:11:53

标签: java jsp struts2 jdbc-odbc

我编写的代码只给出了下拉列表中单个数据的输出。我希望我的下拉列表能够检索并保存表格的fnameuserid列的所有数据。我正在使用struts概念和JSP。请帮助我如何修改我的代码?

 public String subjectAllocation2()throws Exception
  {
   try{

       Map session=ActionContext.getContext().getSession();
       Long idd=(Long)session.get("USERID");

       System.out.println("sss"+idd);
      ResultSet rs=ConnectionDb.getStatement().executeQuery("select USERID,FNAME from    DIP_FACULTY"); 
       ResultSetMetaData metaData = rs.getMetaData();
        int columns = metaData.getColumnCount();
       ArrayList al = new ArrayList();
       while(rs.next())
       {

          for (int i = 1; i <= columns; i++)
           {
             String value1 = rs.getString(i);
               al.add(value1);
           }
       setUserid(rs.getString(1));
       setFname(rs.getString(2));
       System.out.println("The details="+rs.getString(1)+rs.getString(2)); 

        }
       catch(Exception e)
        {
        System.out.println("exception");
         }
       return "subjectAllocation2";
         }

这是JSP代码

<s:form action="addSubject" method="post"  enctype="multipart/form-data">
                <table border="1" cellpadding="15" width="300">

                <tr><td><s:combobox name="semestar" label="Semestar" list="{'1st','2nd','3rd','4th','5th','6th','7th','8th'}"></s:combobox></td>
                <td><s:combobox name="branch" label="Branch" list="{'CSE','IT','EEE','ETC','MECH','EE','CIVIL'}"></s:combobox></td>
                <td><s:radio name="section" label="Section" list="{'A','B'}"/></td></tr>
                <tr><td>

                    <s:select name="fname" label="Faculty name" list="fname"></s:select>

                </td></tr>
            <tr><td><s:combobox name="userid" label="Faculty id" list="userid"></s:combobox></td></tr>
            <tr><td><s:combobox name="subject" label="Subject Name" list="{'Software Engineering','Soft Computing','Computer Graphics','Real Time System','Introduction To Digital Signal Processing','Entreprenaurship Development'}"></s:combobox></td></tr>
                <tr><td><s:select name="sub_code" label="Subject Code" list="{'PCS098','HCS232','WQ1232','PNB342','WQW232','QAZ213'}"></s:select></td></tr>
                <s:checkbox name="theory" label="Theory"></s:checkbox>
                <s:checkbox name="practical" label="Practical"></s:checkbox>





                <tr><td><s:submit value="allocate"/></td><td><s:submit action="reset" value="Reset"/></td></tr>



                </table>
        </s:form>
        <s:property value="msg"/> 

0 个答案:

没有答案