我有一个包含表和值的数据库。我想获取该数据并将其显示在 jsp 页面中。不想在jsp页面中编写查询,分离java类,创建java对象值,然后在jsp的select字段中显示。请帮我...
这是我的java类p
ublic class EmpBean {
public java.util.List dataList(){
ArrayList list=new ArrayList();
try{
Class.forName("driver");
Connection con = DriverManager.getConnection("url", "user", "pwd");
Statement st=con.createStatement();
System.out.println("hiiiii");
ResultSet rs=st.executeQuery("select * from employee");
while(rs.next()){
list.add(rs.getString("name"));
list.add(rs.getString("address"));
list.add(rs.getString("contactNo"));
list.add(rs.getString("email"));
}
System.out.println(rs.getString("contactNo"));
}
catch(Exception e){}
return list;
}
}
//and my jsp file
<%@page language="java" import="java.util.*" %>
<html>
<body>
<table border="1" width="303">
<tr>
<td width="119"><b>Name</b></td>
</tr>
<%Iterator itr;%>
<%EmpBean p = new EmpBean();
List list= (List) p.dataList(); %>
for (itr=list.iterator(); itr.hasNext(); ){
%>
<tr>
<select name="" id="" style="width: 150px;"">
<option value="-1"><%=itr.next()%></option>
</select>
</tr>
<%}%>
</table>
</body>
</html>