JavaWeb综合练习
前台和后台
前台:
-
开发的技术,Java,网页,数据库
-
用户角度
- 面向所有用户
- 功能:查询,新增
后台:
-
开发的技术,Java,网页,数据库
-
用户角度
- 面向管理者
- 功能: 全面
展示全部商品数据
list.jsp
<!--
商品展示
forEach标签属性 varStatus循环变量状态
-->
<c:forEach items="${list}" var="product" varStatus="vs">
<tr onmouseover="this.style.backgroundColor = '#CCCCCC'"
onmouseout="this.style.backgroundColor = '#F5FAFE';">
<td style="CURSOR: hand; HEIGHT: 22px" align="center"
width="18%">${vs.count}</td>
<td style="CURSOR: hand; HEIGHT: 22px" align="center"
width="17%"><img width="40" height="45" src="${product.pimage}"></td>
<td style="CURSOR: hand; HEIGHT: 22px" align="center"
width="17%">${product.pname}</td>
<td style="CURSOR: hand; HEIGHT: 22px" align="center"
width="17%">${product.shop_price}</td>
<!-- 数据表 1表示热门, 0表示 非热门-->
<td style="CURSOR: hand; HEIGHT: 22px" align="center"
width="17%">${product.is_hot==1?"是":"不是"}</td>
<td align="center" style="HEIGHT: 22px"><a
href="${ pageContext.request.contextPath }/admin/product/edit.jsp">
<img
src="${pageContext.request.contextPath}/images/i_edit.gif"
border="0" style="CURSOR: hand">
</a></td>
<td align="center" style="HEIGHT: 22px"><a href="#"> <img
src="${pageContext.request.contextPath}/images/i_del.gif"
width="16" height="16" border="0" style="CURSOR: hand">
</a></td>
</tr>
</c:forEach>
<!-- 商品展示结束-->
删除商品
实现步骤
- 点击删除图片,出现提示框( JS函数 confirm)
- 获取点击商品的主键数据
- 主键提交服务器Servlet
- 主键传递业务层
- 业务层将主键传递dao
- 执行SQL语句删除
- Servlet客户端响应,转发到/findAll
list.jsp
function delProduct(pid) {
if(confirm("确定要删除吗")){
//获取点击的商品的主键 (参数传递)
//主键数据提交服务器Servlet
location.href="${pageContext.request.contextPath}/delProduct?pid="+pid;
}
}
<td align="center" style="<