【发布时间】:2018-06-30 07:27:00
【问题描述】:
enter code here
-
这是从数据库加载数据到jsp的java代码
包道;
import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import model.Category; import utils.DBConnect; public class CategoryDAO { public ArrayList<Category> getListCategory() throws SQLException { Connection connect = DBConnect.getConnection(); ArrayList<Category> listCategory = new ArrayList<>(); String sql = "SELECT * FROM category"; PreparedStatement ps = connect.prepareCall(sql); ResultSet rs = ps.executeQuery(); while (rs.next()) { Category category = new Category(); category.setCategoryID(rs.getInt("CategoryID")); category.setCategoryName(rs.getString("CategoryName")); listCategory.add(category); } return listCategory; }; } -
这是显示数据的html文件,我是加载类
<ul class="drop"> <% for (Category c : cateDao.getListCategory()) { %> <li><a href="product.jsp?category=<%=c.getCategoryID()%>"><%= c.getCategoryName() %></a></li> <% } %> </ul>
错误部分将在评论中发布
【问题讨论】: