1. 程式人生 > >記賬本----3

記賬本----3

text info dbutil glib borde ets sta stl state

今天做的是修改。

<%@ 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{
        margin
-top: 20px; } .b{ font-size: 20px; width: 160px; color: white; background-color: greenyellow; } .tb, td { border: 1px solid black; font-size: 22px; } </style> </head> <body> <% Object message = request.getAttribute("message");
if(message!=null && !"".equals(message)){ %> <script type="text/javascript"> alert("<%=request.getAttribute("message")%>"); </script> <%} %> <div align="center"> <h1 style="color: red;">賬單信息列表</h1> <a href="index.jsp">返回主頁</a> <table class="tb"> <tr> <td>id</td> <td>賬單類型</td> <td>年</td> <td>月</td> <td>日</td> <td>收入</td> <td>支出</td> <td align="center" colspan="2">操作</td> </tr> <c:forEach items="${bills}" var
="item"> <tr> <td>${item.id}</td> <td>${item.type}</td> <td>${item.year}</td> <td>${item.month}</td> <td>${item.day}</td> <td>${item.income}</td> <td>${item.pay}</td> <td><a href="BillServlet?method=getbillbyid2&id=${item.id}">修改</a></td> </tr> </c:forEach> </table> </div> </body> </html>

技術分享圖片

後面部分以後做。

dao層

public List<Bill> modifylist() {
        String sql = "select * from bill";
        List<Bill> modifylist = new ArrayList<>();
        Connection conn = DBUtil.getConn();
        Statement state = null;
        ResultSet rs = null;

        try {
            state = conn.createStatement();
            rs = state.executeQuery(sql);
            Bill bean = null;
            while (rs.next()) {
                int id = rs.getInt("id");
                String type2 = rs.getString("type");
                String year2 = rs.getString("year");
                String month2 = rs.getString("month");
                String day2 = rs.getString("day");
                String income2=rs.getString("income");
                String pay2=rs.getString("pay");
                bean = new Bill(id, type2, year2, month2,day2,income2,pay2);
                modifylist.add(bean);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(rs, state, conn);
        }
        
        return modifylist;
    }

servlet層

    private void getBillById2(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
            req.setCharacterEncoding("utf-8");
            int id = Integer.parseInt(req.getParameter("id"));
            Bill bill = dao.getBillById(id);
            req.setAttribute("bill", bill);
            req.getRequestDispatcher("modify.jsp").forward(req,resp);
            
        }
        
        
        private void modifylist(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
            req.setCharacterEncoding("utf-8");
            List<Bill> bills = dao.modifylist();
            req.setAttribute("bills",bills);
            req.getRequestDispatcher("modifylist.jsp").forward(req,resp);
        }

這些只是能出現上圖那個修改列表,點擊修改進入修改界面。後續再完成。

記賬本----3