how to collect data from table into the dropdown ( jsp)


Web tier: servlets, JSP, Web frameworks: how to collect data from table into the dropdown ( jsp)

  1. hi, I wrote a query and i got rs and i want to put data in dropdown box please tell me how to write data <select></select>.if possible can you send me a sample code in jsp.


  2. hi,
      when u got resultset then it's very simple.u need to put the result in a dropdown.please see this sample code,

     <select name="name">
     on sending the above to browser the dropdown will automatically appear on the browser.try and see.
  3. U might need to add some value to each option ...
    u can use this ...

     <select name="name">
     <option value="<%=rs.getXXX(1)%>"><%=rs.getxxx(1)%>
     <option value="<%=rs.getXXX(2)%>"><%=rs.getxxx(2)%>
     <option value="<%=rs.getXXX(3)%>"><%=rs.getxxx(3)%>
  4. If you wanted to retrieve data for one particular field, store that values in a arraylist and add it and call the array list in your JSP.

    That will resolve your problem of pulling records for a particular field from a table and showing it as a drop down.I think this is your requirement, not the records in the table itself.

  5. Hi, I have written a bean which executes the query and shows the two columns in the table.I want to get this data into the dropdown box(one of the cloumns should be value and the other text for the option field).Also, i am trying to change the values of this drop down box depending on the selection on another drop down box.Could you please help me out in this and mail me or post here the sample code for this.

    I could acheive the above said through Javascript(but that needed hardcoding of the data in the table).I want to avoid hardcoding and select from DB