• 1月11日 家庭小账本(改) 开发记录


    1、页面修改

    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    <jsp:useBean id="now" class="java.util.Date" />
    <fmt:formatDate value="${now}" type="both" dateStyle="long" pattern="yyyy-MM-dd HH:mm:ss" var="currentdate" />
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>添加收支信息页面</title>
    <style type="text/css">
    body{
    background:url("./backs.jpg");
    background-repeat:repeat;
    background-size:1600px 800px;
    background-position-center:100%;
    }
    </style>
    </head>
    <body>
    <form action="/MoneyCount/Addservlet">
    <table align = "center" class="t1" border="1">
    <tr>
    <td colspan="2"><h1>添加收支信息</h1></td>
    </tr>
    <tr>
    <td>收支日期</td>
    <td><input type="text" name = "usedate" value="${currentdate}" readonly="readonly"/></td>
    </tr>
    <tr>
    <td>收支使用人</td>
    <td><input type="text" name = "username"></td>
    </tr>
    <tr>
    <td>收支用途</td>
    <td><input type="text" name = "userused"></td>
    </tr>
    <tr>
    <td>收支金额</td>
    <td><input type="text" name = "usermoney"></td>
    </tr>
    <tr>
    <td>收支状况</td>
    <td>
    <input type="radio" name="used" value="收入">收入
    <input type="radio" name="used" value="支出">支出
    </td>
    </tr>
    <tr>

    <td colspan="2">
    <input type="submit" value="上传">
    <input type="reset" value="清空">
    <input type="button" value="返回" onclick="history.go(-1)">
    </td>
    </tr>
    </table>
    </form>
    </body>
    </html>

    (新增登录界面)

    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <style type="text/css">
    body{
    background:url("./backs.jpg");
    background-repeat:repeat;
    background-size:1600px 800px;
    background-position-center:100%;
    }
    </style>
    </head>
    <body>
    ------------------------------------------------
    用户名或密码输入错误!!!
    ------------------------------------------------
    <form action="/MoneyCount/Loginuserservlet">
    <table align = "center" class="t1" border="1">
    <tr>
    <td colspan="2"><h1>欢迎使用家庭小账本</h1></td>
    </tr>
    <tr>
    <td>用户名</td>
    <td><input type="text" name = "lname"/></td>
    </tr>
    <tr>
    <td>密码</td>
    <td><input type="password" name = "lpwd"/></td>
    </tr>
    <tr>

    <td colspan="2">
    <input type="submit" value="登录">
    <input type="reset" value="清空">
    </td>
    </tr>
    </table>
    </form>
    </body>
    </html>

    ------------信息显示界面增加金额显示---------------------------------

    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="a"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
    <%@ page import = "com.edu.entity.*" %>
    <%@ page import = "java.util.List" %>
    <%@ page import = "com.edu.dao.*" %>
    <%
    String path = request.getContextPath();
    %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <script src="<%=path%> /resource/bs/js/jquery-1.11.1.js"></script> <!-- 引入jquery -->
    <link rel="stylesheet" href="<%=path%>/resource/bs/css/bootstrap.css"> <!-- 引入bootstrap.css -->
    <script src="<%=path%> /resource/bs/js/bootstrap.min.js"></script><!-- 引入bootstrap.min.js -->
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>信息显示</title>
    <style type="text/css">
    body{
    background:url("./backs.jpg");
    background-repeat:repeat;
    background-size:1600px 800px;
    background-position-center:100%;
    }
    </style>
    <script language = "javascript">
    function jump1(){
    window.location.href = "Addused.jsp";
    }
    function jump2(){
    window.location.href = "Updateused.jsp";
    }
    </script>
    <style type="text/css">
    table {
    border: 1px solid black;
    margin: 0 auto;
    }
    td{
    150px;
    border: 1px solid black;
    text-align: center;
    }
    </style>
    </head>
    <body>
    <%!
    int i=0,e=0,sum=0;
    %>
    <%
    Userdao dao = new Userdao();
    List<User> list = dao.showAll();
    request.setAttribute("list", list);
    int i=0,e=0;
    i = dao.IncomeSum();
    e = dao.ExpendSum();
    sum = i-e;
    %>
    <form action="/MoneyCount/Showservlet">
    <table align = "center" class="t1" border="1">
    <tr>
    <td colspan="7" class="text-center"><h2>信息展示</h2></td>
    </tr>
    <tr>
    <td>收支编号</td>
    <td>收支人姓名</td>
    <td>收支用途</td>
    <td>收支状况</td>
    <td>收支金额</td>
    <td>收支日期</td>
    <td>操作</td>
    </tr>
    <c:forEach items="${list}" var="user">
    <tr>
    <td>${user.id }</td>
    <td>${user.username }</td>
    <td>${user.userused }</td>
    <td>${user.used }</td>
    <td>${user.usermoney }</td>
    <td><fmt:formatDate value="${user.usedate}" type="both"/></td>
    <td><a href="Deleteservlet?id=${user.id}" onclick="if(confirm('是否确定删除?')==false)return false">删除</a>
    ||<a href="Updateservlet?id=${user.id}">修改</a></td>
    </tr>
    </c:forEach>
    <tr>
    <td><input type="button" value="添加" onclick="jump1()">|<input type="button" value="返回" onclick="history.go(-1)"></td>
    <td>支出总金额:</td>
    <td><%=e %></td>
    <td>收入总金额:</td>
    <td><%=i %></td>
    <td>总计:</td>
    <td><%=sum %></td>
    </tr>
    <tr>
    <td colspan="7" class="text-center">注:总计数值为正时,收入大于支出;总计数值为负值时,支出大于收入</td>
    </tr>
    </table>
    </form>
    </body>
    </html>

    2、Java代码修改

    public User ResearchId(int id) {
    Connection conn = DbHelper.getConnection();
    String sql = "select * from userno where id = ?";
    ResultSet rst = null;

    User user = new User();
    try {
    PreparedStatement pst = conn.prepareStatement(sql);
    pst.setInt(1, id);
    rst = pst.executeQuery();
    while(rst.next()) {
    user.setId(rst.getInt("id"));
    user.setUsername(rst.getString("username"));
    user.setUserused(rst.getString("userused"));
    user.setUsermoney(rst.getString("usermoney"));
    user.setUsedate(rst.getDate("usedate"));
    user.setUsed(rst.getString("used"));
    }
    rst.close();
    pst.close();
    } catch (SQLException e) {
    // TODO 自动生成的 catch 块
    e.printStackTrace();
    }
    // TODO 自动生成的方法存根
    return user;
    }
    public int IncomeSum(){
    Connection conn = DbHelper.getConnection();
    String sql = "select * from userno where used = ?";
    String snum = null;
    PreparedStatement pst = null;
    int isum = 0;
    try {
    pst = conn.prepareStatement(sql);
    pst.setString(1, "收入");
    ResultSet rst = pst.executeQuery();
    while(rst.next()) {
    User user = new User();
    user.setUsermoney(rst.getString("usermoney"));
    snum = user.getUsermoney();
    isum = isum + Integer.parseInt(snum);
    }
    rst.close();
    pst.close();
    } catch (SQLException e) {
    // TODO 自动生成的 catch 块
    e.printStackTrace();
    }
    return isum;
    }
    public int ExpendSum(){
    Connection conn = DbHelper.getConnection();
    String sql = "select * from userno where used = ?";
    int esum = 0;
    String snum = null;
    try {
    PreparedStatement pst = conn.prepareStatement(sql);
    pst.setString(1, "支出");
    ResultSet rst = pst.executeQuery();
    while(rst.next()) {
    User user = new User();
    user.setUsermoney(rst.getString("usermoney"));
    snum = user.getUsermoney();
    esum = esum + Integer.parseInt(snum);

    }
    rst.close();
    pst.close();
    } catch (SQLException e) {
    // TODO 自动生成的 catch 块
    e.printStackTrace();
    }
    return esum;
    }

    3、阅读构建之法 现代软件工程(第三版)

    4、观看JSP+Servlet+MySql+Tomcat+JDBC项目详细讲解

  • 相关阅读:
    C++中随机函数
    在cocos2d里面如何使用Texture Packer和像素格式来优化spritesheet
    CCParticleSystem粒子系统
    Redis百亿级Key存储方案
    Mongodb亿级数据量的性能测试
    mysql-mongdb-redis
    java常用的几种线程池比较
    Java中的多线程
    MySQL技术内幕InnoDB存储引擎(表&索引算法和锁)
    B+树介绍
  • 原文地址:https://www.cnblogs.com/lx06/p/14415825.html
Copyright © 2020-2023  润新知