我试过了,这是我的尝试请帮助我 ,我需要从我的数据库中填充 jsp 中的组合框
1-jsp页面
<p class="ppp">Category</p>
<jsp:useBean id="categorys" class="database.conDB" scope="page"/>
<select name="categorys" size="1" style="width:196px; padding:5px;" >
<c:forEach var="categ" items="${categorys.categoryNames} ">
<option value="${categ}">${categ} </option>
</c:forEach>
</select>
=========== 2-这是我在 conDB 类中的函数
public String[] getCategory()
{
String query="SELECT category_name FROM books.category;";
Statement statement;
ResultSet resultSet ;
try{
statement=createConnection().createStatement();
resultSet=statement.executeQuery(query);
int count=0;
while(resultSet.next())
count++;
categoryNames=new String[count];
resultSet.first();
do{
categoryNames[count -1]=resultSet.getString("category_name");
count--;
}while(resultSet.next());
}catch(Exception e)
{e.printStackTrace();}
for (int i = categoryNames.length; i > 0; i--)
System.out.println(categoryNames[i - 1]);
return categoryNames;
}