java servlet 输出一个list 到jsp页面 循环在table中
publicListfind_meiricq_smc(Stringsql){Connectioncon=DbConnection_tcc.getConnection();...
public List find_meiricq_smc(String sql) {
Connection con = DbConnection_tcc.getConnection();
sql = "SELECT xuehao, name,kahao FROM ICCO.dbo.V_xsdaoru ";
List<String> lis = new ArrayList<String>();
int id = 0;
try {
PreparedStatement stmt = con.prepareStatement(sql);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
lis.add(rs.getString(1));
lis.add(rs.getString(2));
lis.add(rs.getString(3));
lis.add("");
}
} catch (Exception e) {
Log.log(this, "queryUser:" + e);
e.printStackTrace();
} finally {
ConnTools.close(con);
}
return lis;
}
}
java Struts + Spring +servlet 我从执行这个sql 返回一个lis 而我在Action层 获取list 输出list到jsp页面
List list = service.ussyzbt(sql);
try {
request.setAttribute("list", list);
request.getRequestDispatcher("table-jsp").forward(request,response);
} catch (Exception e) {
e.printStackTrace();
}}
而我在jsp页面 这样获取
ArrayList list = (ArrayList)request.getAttribute("list");
我要怎么遍历这个list 循环在一个table中 展开
Connection con = DbConnection_tcc.getConnection();
sql = "SELECT xuehao, name,kahao FROM ICCO.dbo.V_xsdaoru ";
List<String> lis = new ArrayList<String>();
int id = 0;
try {
PreparedStatement stmt = con.prepareStatement(sql);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
lis.add(rs.getString(1));
lis.add(rs.getString(2));
lis.add(rs.getString(3));
lis.add("");
}
} catch (Exception e) {
Log.log(this, "queryUser:" + e);
e.printStackTrace();
} finally {
ConnTools.close(con);
}
return lis;
}
}
java Struts + Spring +servlet 我从执行这个sql 返回一个lis 而我在Action层 获取list 输出list到jsp页面
List list = service.ussyzbt(sql);
try {
request.setAttribute("list", list);
request.getRequestDispatcher("table-jsp").forward(request,response);
} catch (Exception e) {
e.printStackTrace();
}}
而我在jsp页面 这样获取
ArrayList list = (ArrayList)request.getAttribute("list");
我要怎么遍历这个list 循环在一个table中 展开
展开全部
通过jstl的<c:foreach>标签进行遍历,简单例子如下:
<c:if test="${!empty xxxList}">
<c:forEach items="${xxxList}" var="o" varStatus="st">
<tr>
<td align="center">${o.merchantName }</td>
<td align="center">${o.consignee }</td>
<td align="center">${o.orderAmount }</td>
</tr>
</c:forEach>
</c:if>
有问题欢迎提问,满意请采纳,谢谢!
<c:if test="${!empty xxxList}">
<c:forEach items="${xxxList}" var="o" varStatus="st">
<tr>
<td align="center">${o.merchantName }</td>
<td align="center">${o.consignee }</td>
<td align="center">${o.orderAmount }</td>
</tr>
</c:forEach>
</c:if>
有问题欢迎提问,满意请采纳,谢谢!
推荐于2017-09-04 · 知道合伙人软件行家
关注
展开全部
<table width="60%" border="1">
<tr>
<th>学号</th>
<th>姓名</th>
</tr>
<%
ArrayList list = (ArrayList)request.getAttribute("list");
for(int i=0;i<list.size();i++){
if(i%3==0){
out.println("<tr>");
}
if(i%3==2){
out.println("</tr>");
}else{
out.println("<td>"+list.get(i)+"</td>");
}
}
%>
</table>
<tr>
<th>学号</th>
<th>姓名</th>
</tr>
<%
ArrayList list = (ArrayList)request.getAttribute("list");
for(int i=0;i<list.size();i++){
if(i%3==0){
out.println("<tr>");
}
if(i%3==2){
out.println("</tr>");
}else{
out.println("<td>"+list.get(i)+"</td>");
}
}
%>
</table>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询