




免费预览已结束,剩余13页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
软 件 学 院课程设计报告书课程名称 JavaEE 课程设计 设计题目 个人财务系统 专业班级 软件工程 学 号 xxxxxxxxx07 姓 名 xxxxx 指导教师 姜彦吉 2011 年 12 月1 设计时间2011年12月12日12月16日2 设计目的JavaEE课程设计是对所学JavaEE与中间件课程的小结,是提高学生对所学知识综合应用能力的一种方式,是集中实践性环节之一。要求同学们对课程中所学习到的知识综合运用,开发有一定规模的Java Web程序。3设计任务设计个人帐务管理系统,要求用户以合法的身份登录后可以对系统进行操作,用户可以查看,添加,删除和计算某段时间内帐务的收入和支出信息等。帐务信息包括收入和支出两种,还有日期和备注。4 设计内容 4.1 设计题目个人财务管理系统 4.1.1系统功能要求用只有拥有合法身份才能登录系统,用以合法身份登录后可以产看帐务信息、添加帐务信息、删除帐务信息、分别统计某个时间段内的收入和支出总额。4.1.2 数据库存储要求 数据的存储要求:收入数额,支出数额,备注,日期4.1.3数据库的设计 表1(数据存储要求)列名称数据类型长度idbigint8incomemoneymoney8costmoneymoney8recordvarchar50timevarchar8图1(数据库存储数据)4.1.4系统构造关系登陆窗口 no密码yes操作界面 查询保存计算帐目删除图2(jsp页面构造)Jsp页面传递参数调用servlet类参数计算方法servlet删除方法servlet查询方法servlet保存方法servlet删除方法dao类查询方法dao类保存方法dao类计算方法dao类图3(Java类功能调用)4.2 Jsp 页面设计4.2.1登录界面 图4(登录界面)代码如下:欢迎登陆个人财务统计系统! 用户名称:用户密码: 4.2.2登录成功界面 图5(登录成功查询界面) 代码如下: 欢迎登录: 增加帐目明细请输入: 收入数额: 支出数额: 附加备注: 输入日期: 查询帐目明细请点击: 删除帐目信息请如下: 请输入要 删除帐目的日期: 起始Id号: 终止Id号: 4.2.3查询结果界面图6(查询结果界面)4.3Java方法设计4.3.1Servlet类控制增删改操作的servlet类代码设计如下:public class AccountController extends HttpServlet protected void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException doPost(request,response);protected void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException int arg=Integer.parseInt(request.getParameter(arg); switch(arg) case 1:this.findAllAccount(request,response); break; case 2:this.saveAllAccount(request,response); break; case 3:this.deleteSomeAccount(request,response); break; case 4:this.caculateAccount(request,response); break; protected void caculateAccount(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException int a=0;int b=0; a=Integer.parseInt(request.getParameter(id); b=Integer.parseInt(request.getParameter(id); AccountDao accountDao=new AccountDao(); List list2=accountDao.caculateAccount(a,b); request.setAttribute(result,list2); RequestDispatcher rdt1=request.getRequestDispatcher(/Result1.jsp); rdt1.forward(request, response);public void findAllAccount(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException AccountDao accountDao=new AccountDao(); List list=accountDao.findAllAccount(); request.setAttribute(accounts, list); RequestDispatcher rdt=request.getRequestDispatcher(/Result.jsp); rdt.forward(request, response); public void saveAllAccount(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException request.setCharacterEncoding(gbk); double incomemoney=0.0; double costmoney=0.0; incomemoney=Double.parseDouble(request.getParameter(incomemoney); costmoney=Double.parseDouble(request.getParameter(costmoney); String record=(String)request.getParameter(record); String time=(String)request.getParameter(time); MyAccount myAccount=new MyAccount(); myAccount.setIncomemoney(incomemoney); myAccount.setCostmoney(costmoney); myAccount.setRecord(record); myAccount.setTime(time); AccountDao accountDao=new AccountDao(); try accountDao.saveAllAccount(myAccount); catch(Exception e) e.printStackTrace(); this.findAllAccount(request,response); public void deleteSomeAccount(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException request.setCharacterEncoding(gbk); String time=request.getParameter(time); MyAccount myAccount=new MyAccount(); myAccount.setTime(time); AccountDao accountDao=new AccountDao(); try accountDao.deleteSomeAccount(myAccount); catch(Exception e) e.printStackTrace(); this.findAllAccount(request, response); 密码验证的Servlet类的代码如下:public class LoginServlet extends HttpServlet public void doGet(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException doGet(req,resp);public void doPost(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException String username=req.getParameter(username); String password=req.getParameter(password); User user=new User(); user.setUsername(username); user.setPassword(password); HttpSession session=req.getSession(); String forward=; if(UserService.CheckLogin(user) forward=/Search.jsp; session.setAttribute(name, username); else forward=/error.jsp; RequestDispatcher rd=req.getRequestDispatcher(forward); rd.forward(req,resp); 4.3.2Dao类密码验证的Dao类代码设计如下:public class UserService public static boolean CheckLogin(User user) if(user.getUsername().equals(lb)&user.getPassword().equals(123) return true; return false; 帐务添加查询计算的Dao类代码设计如下:public class AccountDao private Connection conn; public List findAllAccount() conn=DBCon.getConnection(); String listSQL=select * from myaccount; List list=new ArrayList(); try PreparedStatement psmt=conn.prepareStatement(listSQL); ResultSet rs=psmt.executeQuery(); while(rs.next() MyAccount account=new MyAccount(); account.setId(rs.getInt(1); account.setIncomemoney(rs.getDouble(2); account.setCostmoney(rs.getDouble(3); account.setRecord(rs.getString(4); account.setTime(rs.getString(5); list.add(account); mit(); return list; catch(Exception e) e.printStackTrace(); finally if(conn!=null) try conn.close(); catch(SQLException e) e.printStackTrace(); return list; public boolean saveAllAccount(MyAccount account)throws Exception conn=DBCon.getConnection(); String listSQL=insert into myaccount values(?,?,?,?); PreparedStatement psmt=conn.prepareStatement(listSQL); try psmt.setDouble(1, account.getIncomemoney(); psmt.setDouble(2, account.getCostmoney(); psmt.setString(3, account.getRecord(); psmt.setString(4, account.getTime(); psmt.executeUpdate(); mit(); return true; catch(SQLException e) conn.rollback(); e.printStackTrace(); return false; public boolean deleteSomeAccount(MyAccount account)throws Exception conn=DBCon.getConnection(); String listSQL=delete from myaccount where time=? ; PreparedStatement psmt=conn.prepareStatement(listSQL); try psmt.setString(1, account.getTime(); psmt.executeUpdate(); mit(); return true; catch(SQLException e) conn.rollback(); e.printStackTrace(); return false; public List caculateAccount(int x,int y) conn=DBCon.getConnection(); double incometotal=0.0; double costtotal=0.0; int i=0; List list2=new ArrayList(); try MyAccount account=new MyAccount(); for( i=x;i=y;i+) String listSQL1=selct incomemoney from myaccount where id=i; PreparedStatement psmt1=conn.prepareStatement(listSQL1); ResultSet rs1=psmt1.executeQuery(); psmt1.execute(); incometotal=incometotal+rs1.getDouble(2); String listSQL2=select costmoney from myaccount where id=i; PreparedStatement psmt2=conn.prepareStatement(listSQL2); ResultSet rs2=psmt2.executeQuery(); psmt2.execute(); costtotal=costtotal+rs2.getDouble(3); mit(); account.setIncomemoney(incometotal); account.setCostmoney(costtotal); list2.add(account); return list2; catch(SQLException e) e.printStackTrace(); return list2; 4.3.3数据库连接类数据库连接代码如下:public class DBCon public static Connection getConnection() String url=jdbc:microsoft:sqlserver:/localhost:1433;databaseName=myaccountbase;String user=sa;String psw=sa;Connection conn=null;tryClass.forName(com.microsoft.jdbc.sqlserver.SQLServerDriver);catch(ClassNotFoundException e)e.printStackTrace();tryconn=DriverManager.getConnection(url, user,
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 店铺股份合同协议书
- 废弃文具捐助协议书
- 引进高校人才协议书
- 房屋销售口头协议书
- 库存农机转让协议书
- 房屋大修合同协议书
- 情侣搞笑和好协议书
- 房贷合同解除协议书
- 征地果树补偿协议书
- 房产利润分红协议书
- 2024(统编版)语文七年级上册《西游记》真题+综合题练习(学生版+解析版)
- 中国青铜时代(张光直)(历史-中国-史前史)
- 企业财务管理毕业论文范文
- 医院员工价值取向培训
- DB11T 2194-2023 防汛隐患排查治理规范在建工程
- 风机基础降水施工实施方案
- 门禁系统施工技术方案
- 《婴幼儿健康管理》课件-任务四 婴幼儿健康档案建设与管理
- 【出口退税管理探究的国内外探究综述4300字】
- 参观河南省博物院
- 2024版小学语文新课程标准
评论
0/150
提交评论