servlet查询结果集返回jsp页面显示
来源:百度知道 编辑:UC知道 时间:2024/06/02 05:52:32
使用jstl表达式
<c:forEach items="${LIST}" var="list">
姓名:${list[0]}
年龄:${list[1]}
</c:forEach>
/*注释:LIST为你的结果集对象 var则是对应结果集的声明的变量
${}为EL表达式 list[0]是查询的字段,例如select name,age from student. name为list[0] age为list[1]依此类推
*/
首先在dao写一个 方法 返回list
String sql = "select * from Employee where id=?";
PreparedStatement ps=conn.getConn().prepareStatement(sql);
ps.setInt(1, id);
ResultSet rs=ps.executeQuery();
List<Employee > list = new ArrayList<Employee >();
while (rs.next()){
Employee e = new Employee();
bao.setId(rs.getInt("id"));
bao.setName(rs.getString("name"));
list.add(bao);
然后在界面中调用list 遍历list 显示就OK了
<%
for( Employee e : list){
%>
<td><%=e.getId()