家庭記賬本小程序之刪(java web基礎版四)
阿新 • • 發佈:2019-02-26
src image ngs type -s Coding ava left utf
實現刪除消費賬單
1.main_left.jsp中該部分,調用Servlet中delete方法
2.Servlet中delete方法,調用Dao層list方法,跳轉到del.jsp頁面
3.Dao層list方法
4.del.jsp,調用Servlet中的del方法
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <style> .a{ font-size: 20px; } </style> </head> <body> <% Object message = request.getAttribute("message"); if(message!=null && !"".equals(message)){ %> <script type="text/javascript"> alert("<%=request.getAttribute("message")%>"); </script> <%} %> <table class="a"> <tr> <td>id</td> <td>消費名稱</td> <td>消費金額</td> <td>消費日期</td> </tr> <%int i=0;%> <c:forEach items="${courses}" var="item"> <tr <%if(i%2==0){ %>bgcolor="#F0F8FF"<%} %>> <td>${item.id}</td> <td>${item.name}</td> <td>${item.money}</td> <td>${item.date}</td> <td><a onclick="return check()" href="ShangServlet?method=del&id=${item.id}">刪除</a></td> </tr> <%i++; %> </c:forEach> </table> <script type="text/javascript"> function check() { if (confirm("真的要刪除嗎?")){ return true; }else{ return false; } } </script> </body> </html>
5.Servlet中的del方法,調用Dao層delete方法
6.Dao層delete方法,實現與數據庫的操作,添加成功
總結:
Servlet?method=delete --> Dao?method=list --> del.jsp --> Servlet?method=del --> Dao?method=delete
家庭記賬本小程序之刪(java web基礎版四)