![]() |
#2
cnfarer2010-06-01 07:51
|
这是jsp页面:
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'selectstu.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body bgcolor="lightblue"><center>
<jsp:useBean id="s" scope="session" class="wn.Student">
<jsp:setProperty property="*" name="s"/>
</jsp:useBean>
<center><font size="5" color="blue">查找学生信息如下:<br></center>
<hr><table border="2">
<tr>
<td>学号 </td>
<td>姓名 </td>
<td>性别 </td>
<td>年龄 </td>
<td>班级 </td>
<td></td><td></td></tr>
<%
StudentOperation so=new StudentOperation();
List list=so.select();
try{
int i=0;
Iterator it=list.iterator();
while(it.hasNext()){
s=(Student)it.next();
i++;
//String sno=s.getSno();
%>
<tr>
<td><%=s.getSno() %></td>
<td><%=s.getName() %></td>
<td><%=s.getSex() %></td>
<td><%=s.getAge() %></td>
<td><%=s.getClno() %></td>
</tr>
<%
//s.print();
}
}
catch(Exception e)
{e.printStackTrace();} %>
</table></center>
</body>
</html>
这是方法类里的select方法:
public List select() throws Exception{
Connection conn=ConnectionTest.getConnection();
Statement stmt=conn.createStatement();
String sql="select * from student";
List list=new ArrayList();
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){
Student s=new Student();
s.setSno(rs.getString("sno"));
s.setName(rs.getString("name"));
s.setSex(rs.getString("sex"));
s.setAge(rs.getInt("age"));
s.setClno(rs.getString("clno"));
list.add(s);
}
rs.close();
return list;
}//查询操作
查询到的都是最后一行的数据,而且有几行数据就有几行相同的,请问哪里出了问题?
谢谢啦!