I need to know the method to load the combobox dynamically from the array obtained from a bean.
I have written a bean to get the data from database and store it in an array .
<table>
<% for (int i=0; i < aResult.size(); i++) { %>
<tr>
<td>
<% out.print(aResult.elementAt(i)); %>
</td>
</tr>
<% } %>
</table>
</body>
</html>
I have a bean defined as follows. The path is
C:\Program Files\Apache Tomcat 4.0\webapps\examples\WEB-INF\classes\select
DSN name : Studentdb , table : stud , fields sno,sname
package select;
import java.sql.*;
import java.util.Vector;
/**
* DataBaseSelect.java
* Written by Morgan Catlin
* August 19, 1999
*
* Variables:
* Vector result = where I put the results of a select query
*
* Methods:
* Vector getResult() = returns result
* void setResult() = sets result
* String connect() = connects to a database
* String select() = selects information from a database
*/
public class DataBaseSelect {
private Vector result;
public DataBaseSelect() {
result = new Vector();
} // constructor DataBaseSelect
/**
* Accessor for result
**/
public Vector getResult() {
return result;
}
/**
* Mutator for result
**/
public void setResult(Vector avector) {
result = avector;
}
} // class DataBaseSelect
The problem is
In the jsp file after the statement
<% out.print(aResult.elementAt(i)); %>
I want to add the elements in the array into a combo box
Iam not able to do so..
I tried to use the following code
<select name="id">
<table>
<% for (int i=0; i < aResult.size(); i++) { %>
<table>
<% for (int i=0; i < aResult.size(); i++) { %>
<tr>
<td>
<% out.print(aResult.elementAt(i)); %>
</td>
</tr>
<% } %>
</table>
instead of this
use this syntax
<table>
<tr>
<td>
<select name="combo" >
<% for (int i=0; i < aResult.size(); i++) { %>
<option value="" ><%=aResult.elementAt(i)%>
</option>
</td>
</tr>
<% } %>
</table>
that'd fill your combobox
Salih Sipahi
Software Engineer.
City of Istanbul Turkey
s.sipahi@sahinlerholding.com.tr
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.