求大神赐教,我在java中写的jsp代码,其中的一个for循环,为什么显示不了数据,代码如下:
<%for(inti=0;i<products.size();i++){Productp=products.get(i);%><tr><tdclass="altbg2"a...
<%
for (int i = 0; i < products.size(); i++) {
Product p = products.get(i);
%>
<tr>
<td class="altbg2" align="center">
<input type="checkbox" name="id" value="<%=p.getId()%>"/>
</td>
<td class="altbg1" align="center" nowrap="nowrap">
<%=p.getId()%>
</td>
<td class="altbg2" align="center">
<%=p.getName()%>
</td>
<td class="altbg1" align="center">
<%=p.getDescr()%>
</td>
<td class="altbg1" align="center">
<span id="<%=p.getId()%>" style="background:red" onclick="changeToInput(this.id)" value="<%=p.getNormalPrice() %>">
<%=p.getNormalPrice() %>
</span>
</td>
<td class="altbg1" align="center">
<%=p.getMemberPrice()%>
</td>
<td class="altbg1" align="center">
<%=new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(p.getPdate())%>
</td>
<td class="altbg1" align="center">
<%=p.getCategory().getName()%>
</td>
<td class="altbg1" align="right">
<a target="detail" href="ProductDelete.jsp?id=<%=p.getId()%>" onclick="return confirm('真的要删?')">删</a>
<a target="detail" href="ProductModify.jsp?id=<%=p.getId()%>">改</a>
<a target="detail" href="ProductUpload.jsp?id=<%=p.getId()%>">上传</a>
</td>
</tr>
<%
}
%>
取products的代码:
public List<Product> getProducts() {
Connection conn = DB.getConn();
Statement stmt = DB.getStatement(conn);
String sql = "select * from product order by pdate desc";
ResultSet rs = DB.getResultSet(stmt, sql);
List<Product> products = new ArrayList<Product>();
try {
while (rs.next()) {
Product p = getProductFromRs(rs);
products.add(p);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DB.close(stmt);
DB.close(rs);
DB.close(conn);
}
return products;
} 展开
for (int i = 0; i < products.size(); i++) {
Product p = products.get(i);
%>
<tr>
<td class="altbg2" align="center">
<input type="checkbox" name="id" value="<%=p.getId()%>"/>
</td>
<td class="altbg1" align="center" nowrap="nowrap">
<%=p.getId()%>
</td>
<td class="altbg2" align="center">
<%=p.getName()%>
</td>
<td class="altbg1" align="center">
<%=p.getDescr()%>
</td>
<td class="altbg1" align="center">
<span id="<%=p.getId()%>" style="background:red" onclick="changeToInput(this.id)" value="<%=p.getNormalPrice() %>">
<%=p.getNormalPrice() %>
</span>
</td>
<td class="altbg1" align="center">
<%=p.getMemberPrice()%>
</td>
<td class="altbg1" align="center">
<%=new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(p.getPdate())%>
</td>
<td class="altbg1" align="center">
<%=p.getCategory().getName()%>
</td>
<td class="altbg1" align="right">
<a target="detail" href="ProductDelete.jsp?id=<%=p.getId()%>" onclick="return confirm('真的要删?')">删</a>
<a target="detail" href="ProductModify.jsp?id=<%=p.getId()%>">改</a>
<a target="detail" href="ProductUpload.jsp?id=<%=p.getId()%>">上传</a>
</td>
</tr>
<%
}
%>
取products的代码:
public List<Product> getProducts() {
Connection conn = DB.getConn();
Statement stmt = DB.getStatement(conn);
String sql = "select * from product order by pdate desc";
ResultSet rs = DB.getResultSet(stmt, sql);
List<Product> products = new ArrayList<Product>();
try {
while (rs.next()) {
Product p = getProductFromRs(rs);
products.add(p);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DB.close(stmt);
DB.close(rs);
DB.close(conn);
}
return products;
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询