记账本------4
修改的后半部分内容。
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%> <!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;} </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: cyan;">记账信息修改</h1><a href="index.jsp">返回主页</a><form action="BillServlet?method=modify" method="post" οnsubmit="return check()"><div class="a">账单类型<input type="text" id="type" name="type" value="${bill.type}"/></div><div class="a">年<input type="text" id="year" name="year" value="${bill.year}"/></div><div class="a">月<input type="text" id="month" name="month" value="${bill.month}"/></div><div class="a">日<input type="text" id="day" name="day" value="${bill.day}"/></div><div class="a">收入<input type="text" id="income" name="income" value="${bill.income}"/></div><div class="a">支出<input type="text" id="pay" name="pay" value="${bill.pay}"/></div><input type="hidden" id="id" name="id" value="${bill.id}"/><div class="a"><button type="submit" class="b">修 改</button></div></form></div></body> </html>
dao层到目前为止所有的
package com.bill.dao; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.List;import com.bill.util.DBUtil; import com.bill.been.Bill; @SuppressWarnings("unused") public class BillDao { //-----------------------------------------------------------------------------------------------------------------------------public boolean add(Bill bill) {String sql = "insert into bill(type,year,month,day,income,pay) values('" + bill.getType() + "','" + bill.getYear() + "','"+bill.getMonth()+"','"+bill.getDay()+"','"+bill.getIncome()+"','"+bill.getPay()+"')";Connection conn = DBUtil.getConn();//调用方法连接数据库Statement state = null;boolean f = false;int a = 0 ;try { //监视大括号内的代码state = conn.createStatement();a = state.executeUpdate(sql);} catch (Exception e) { //捕获错误 e.printStackTrace();} finally {//关闭z 连接 DBUtil.close(state, conn);}if (a > 0) {f = true;}return f;}//---------------------------------------------------------------------------------------------------------------------------- public Bill getBillById(int id) {String sql = "select * from bill where id ='" + id + "'";Connection conn = DBUtil.getConn();Statement state = null;ResultSet rs = null;Bill bill = null;try {state = conn.createStatement();rs = state.executeQuery(sql);while (rs.next()) {String type = rs.getString("type");String year = rs.getString("year");String month = rs.getString("month");String day = rs.getString("day");String income = rs.getString("income");String pay = rs.getString("pay");bill = new Bill(id, type, year, month,day,income,pay);}} catch (Exception e) {e.printStackTrace();} finally {DBUtil.close(rs, state, conn);}return bill;}public List<Bill> dellist() {String sql = "select * from bill";List<Bill> dellist = 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);dellist.add(bean);}} catch (SQLException e) {e.printStackTrace();} finally {DBUtil.close(rs, state, conn);}return dellist;}public boolean delete (int id) {boolean f = false;String sql = "delete from bill where id='" + id + "'";Connection conn = DBUtil.getConn();Statement state = null;int a = 0;try {state = conn.createStatement();a = state.executeUpdate(sql);} catch (SQLException e) {e.printStackTrace();} finally {DBUtil.close(state, conn);}if (a > 0) {f = true;}return f;} //--------------------------------------------------------------------------------------------------------------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;}public boolean modify(Bill bill) {String sql = "update bill set type='" + bill.getType() + "', year='" + bill.getYear() + "',month='" + bill.getMonth()+ "',day='"+bill.getDay()+"',income='"+bill.getIncome()+"',pay='"+bill.getPay()+"'where id='" + bill.getId() + "'";Connection conn = DBUtil.getConn();Statement state = null;boolean f = false;int a = 0;try {state = conn.createStatement();a = state.executeUpdate(sql);} catch (SQLException e) {e.printStackTrace();} finally {DBUtil.close(state, conn);}if (a > 0) {f = true;}return f;}
servlet层到目前位置所有的
package com.bill.servlet; import java.io.IOException; import java.util.List;import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;import com.bill.dao.BillDao; import com.bill.been.Bill; @WebServlet("/BillServlet") public class BillServlet extends HttpServlet{private static final long serialVersionUID = 1L;public BillServlet() {super();}BillDao dao=new BillDao();protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {req.setCharacterEncoding("utf-8");String method = req.getParameter("method");if ("add".equals(method)) {add(req, resp);}else if ("getbillbyid".equals(method)) {getBillById(req, resp);}else if ("dellist".equals(method)) {dellist(req,resp);}else if ("delete".equals(method)) {delete(req,resp);}else if ("getbillbyid2".equals(method)) {getBillById2(req, resp);}else if ("modifylist".equals(method)) {modifylist(req,resp);}else if ("modify".equals(method)) {modify(req,resp);}else if ("search".equals(method)) {search(req,resp);}} //------------------------------------------------------------------------------------------------------private void add(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {// TODO Auto-generated method stubString type = req.getParameter("type");String year = req.getParameter("year");String month = req.getParameter("month");String day = req.getParameter("day");String income = req.getParameter("income");String pay = req.getParameter("pay");Bill bill=new Bill(type,year,month,day,income,pay);if(dao.add(bill)) {req.setAttribute("message", "保存成功!");req.getRequestDispatcher("add.jsp").forward(req, resp);}else {req.setAttribute("message", "保存失败!");req.getRequestDispatcher("add.jsp").forward(req, resp);}}//------------------------------------------------------------------------------------------------------ private void getBillById(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("delete.jsp").forward(req,resp);}private void dellist(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {req.setCharacterEncoding("utf-8");List<Bill> bills = dao.dellist();req.setAttribute("bills", bills);req.getRequestDispatcher("dellist.jsp").forward(req,resp);}private void delete(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{req.setCharacterEncoding("utf-8");int id = Integer.parseInt(req.getParameter("id"));dao.delete(id);req.setAttribute("message", "删除成功");req.getRequestDispatcher("index.jsp").forward(req,resp);} //---------------------------------------------------------------------------------------------------------------------------------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);}private void modify(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{req.setCharacterEncoding("utf-8");int id = Integer.parseInt(req.getParameter("id"));String type = req.getParameter("type");String year = req.getParameter("year");String month = req.getParameter("month");String day = req.getParameter("day");String income = req.getParameter("income");String pay = req.getParameter("pay");Bill bill = new Bill(id, type, year, month,day,income,pay);dao.modify(bill);req.setAttribute("message", "修改成功");req.getRequestDispatcher("BillServlet?method=modifylist").forward(req,resp);}
效果展示
转载于:https://www.cnblogs.com/birdmmxx/p/10409430.html
记账本------4相关推荐
- 20190226-利用序列化完成小型记账程序
写一个记账程序,每天收入多少,支出多少,总额剩多少,使用序列化方式保存信息 算法: 1.读取输入格式为 value|classify,其中value整数表示收入,负数表示支出 2.income列表存取 ...
- fb50 sap 报记账码未定义_SAP隐秘的角落:记账代码Posting Key
从会计角度来看,记账其实只有借和贷.有借必有贷,借贷必相等.但是在SAP中的借贷确有着不同的Posting Key. 刚接触SAP的时候,对借贷的印象是这样的.对客户收入记账是: 01客户代码 Cus ...
- Java课程寒假之开发记账本软件(网页版)之二
一.实现基础功能之一(记账) 一个记账本最基础之一的功能就是记账,所以也是首先要解决的问题,我选择了上学期使用的MySQL数据库来对账本进行存储. 我选择记账的方法是分开记账,就是支出放在一个表,收入 ...
- 区块链项目实战 - 使用以太坊/智能合约solidity,全栈开发区块链借贷记账小应用,含完整源码
本文使用区块链平台以太坊+智能合约实现一个区块链记账的功能,具体为: 借款人和贷款人以及数额被记录在区块链中.使用区块链地址来表示借款人或者贷款人. 若一个借款人多次向一个贷款人借钱,更新所有的数额之 ...
- 独家 | 一文读懂Corda分布式记账技术
作者:Dan Newton 翻译:申利彬 校对:丁楠雅 本文约2600字,建议阅读10分钟. 本文为你介绍借鉴了区块链的部分特性的分布式记账技术,并分析其背后的原因. 什么是Corda? 最近我开始了 ...
- 工信部:筹建全国首个区块链和分布式记账标准化技术委员会
作者:李秀琴 在3.15即将来临之时,我国工信部给区块链行业又带来了一大利好消息. 3月12日,工业和信息化部(以下简称工信部)在官网发布公告称,其正在就筹建全国区块链和分布式记账技术标准化技术委员会 ...
- 记账本开发进程第一天
做记账本的时候没有及时把博客园写下来,所以导致现在记得不是太清楚了,但是大体上应该是这样的. 第一天信心很足,去网上查了有关于github的相关解释.然后又忽然发现了一个好东西LBulider,是一个 ...
- [UWP小白日记-3]记账项目-1
原文:[UWP小白日记-3]记账项目-1 学了一段时间的UWP,来个项目试试手. 本来是想边做边学MVVMLight的结果感觉MVVM对于萌新来说太高难,以后再把这个项目改造成MVVMLight框架的 ...
- iOS开发实战-时光记账Demo 本地数据库版
现在记账APP也是用途比较广泛 自己写了个简单的demo 欢迎指正 效果 分析 1.思维推导 首先简单的做了下思维推导 2.文件结构 大致框架想好后就可以着手开始准备了 数据库管理:coreData ...
- 奚记--最简洁的记账软件
最近几天一直在开发个人的第一个应用--奚记.在昨天我的第一个Android应用终于在豌豆荚平台上架了,真的是激动万分啊,今天就不要脸的来推广介绍下我的软件,让各位见笑我的幼稚的作品了. 奚记,是一款最 ...
最新文章
- NumPy中可用的聚合函数
- Android之选项菜单创建
- C#判断年份是否为闰年
- MYSQL MVCC实现及其机制
- java编程中的di是什么_java-在Spring IoC / DI中使用@Component注释对接口...
- 计算机上没有启动程序怎么办,Win7开机不加载启动项怎么办
- 联合使用 HTML 5、地理定位 API
- Leetcode-5199 Smallest String With Swaps(交换字符串中的元素)
- php的 静态变量,PHP之static静态变量详解
- mysql的存储过程的参数,MySQL存储过程中的参数
- 一键部署Zabbix客户端
- awk 匹配_20分钟降服awk
- Codeforces Round #372 (Div. 1) B. Complete The Graph
- 一维连续傅里叶变换和逆变换公式的一种推导
- CodeForces 1009D Relatively Prime Graph 贪心+枚举
- 有人知道要怎么用c++提取出文本里面的信息吗,例如把这个表格里的所有住户账号,密码提取出来
- WordBias | 可视化文本中的偏见(刻板印象)
- 聊一聊B端和C端产品的区别
- c++ STL 容器
- 西游之路——python全栈——报障系统之后台管理
热门文章
- element ui 获取文件的路径_win10使用WinAppDriver实现UI自动化
- linux内核层是什么,从用户层到内核层 - Linux内核中的信号机制_Linux编程_Linux公社-Linux系统门户网站...
- java的编译代码混淆
- fastjson字段改名/设置别名
- selenium:反反爬拖动验证码
- mysql 删除重复数据_MySQL查找和删除重复数据
- HTML5数据库建模,HTML5的五种客户端离线存储方案
- 舞力全开加速_国行舞力全开评测:丝滑得不像是育碧服务器!
- java类用三木运算编译不生效_Java 中的三目运算符使用不当所导致的问题
- htc m8 wp android,区别仅系统?WP/Android两版HTC One M8对比