--------------------------------listProducts.jsp------------------------------------
<table class="table table-striped" width="1024">
<thead>
<tr>
<th>商品全称</th>
<th>品牌</th>
<th>生产厂家</th>
<th>计量单位</th>
<th>零售价</th>
<th>所属分类</th>
<th>操作</th>
</tr>
</thead>
<c:forEach items="${cs}" var="b">
<tr>
<td>${b.name}</td>
<td>${b.brand}</td>
<td>${b.address}</td>
<td>${b.unit}</td>
<td>${b.outprice}</td>
<td>${b.category_id}</td>
<td>
<a href="javascript:delOne('${b.id}')">详细参数</a>
<a href="${pageContext.request.contextPath}/servlet/ManagerServlet?operation=editCategory&categoryId=${b.id}">修改</a>
<a href="javascript:delOne('${b.id}')">删除</a>
</td>
</tr>
</c:forEach>
</table>
-------------------------- ManagerServlet------------------------------
public class ManagerServlet extends HttpServlet {
private BusinessService s = new BusinessServiceImpl();
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String operation = request.getParameter("operation");
if("showAllProduct".equals(operation)){
showAllProduct(request, response);
}
}
private void showAllProduct(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
List<Product> cs = s.findAllProducts();
request.setAttribute("cs", cs);
request.getRequestDispatcher("/manager/listProducts.jsp").forward(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
----------------------------BusinessServiceImpl.java----------------------
public class BusinessServiceImpl implements BusinessService {
private ProductDao pDao = new ProductDaoImpl();
public List<Product> findAllProducts() {
return pDao.findAll();
}
}
------------------------------------ProductDaoImpl.java-------------------------
public class ProductDaoImpl implements ProductDao {
private QueryRunner qr = new QueryRunner(DBCPUtil.getDataSource());
public List<Product> findAll() {
try {
return qr.query("select * from product", new BeanListHandler<Product>(Product.class));
} catch (SQLException e) {
throw new DaoException(e);
}
}