1、软 件 学 院课程设计汇报书课程名称 JavaEE 课程设计 设计题目 个人财务系统 专业班级 软件工程 学 号 姓 名 指导老师 年 12 月目录1 设计时间32 设计目标33设计任务34 设计内容34.1 设计题目34.1.1系统功效要求34.1.2 数据库存放要求34.2 Jsp 页面设计34.2.1登录界面34.2.2登录成功界面44.2.3查询结果界面64.2.4计算结果界面74.3Java方法设计74.3.1Servlet类74.3.2Dao类124.3.3domain类174.3.4数据库连接类195 总结和展望20参考文件21成绩评定211 设计时间12月12日12月16日2
2、设计目标JavaEE课程设计是对所学JavaEE和中间件课程小结,是提升学生对所学知识综合应用能力一个方法,是集中实践性步骤之一。要求同学们对课程中所学习到知识综合利用,开发有一定规模Java Web程序。3设计任务设计个人帐务管理系统,要求用户以正当身份登录后能够对系统进行操作,用户能够查看,添加,删除和计算某段时间内帐务收入和支出信息等。帐务信息包含收入和支出两种,还有日期和备注。4 设计内容 4.1 设计题目个人财务管理系统 4.1.1系统功效要求用只有拥有正当身份才能登录系统,用以正当身份登录后能够产看帐务信息、添加帐务信息、删除帐务信息、分别统计某个时间段内收入和支出总额。4.1.2
3、 数据库存放要求 收入支出数额,日期和备注4.2 Jsp 页面设计4.2.1登录界面 图1(登录界面)代码以下:欢迎登陆个人财务统计系统! 用户名称:用户密码: 4.2.2登录成功界面 图2(登录成功查询界面) 代码以下: 欢迎登录: 增加帐目明细请输入: 收入数额: 支出数额: 附加备注: 输入日期: 查询帐目明细请点击: 删除帐目信息请以下: 请输入要 删除帐目标日期: 起始Id号: 终止Id号: 4.2.3查询结果界面图3(查询结果界面)代码以下: 您帐务明细以下: 帐目序号 收入数额 支持数额 附加备注 统计日期 % List list=(List)request.getAttribu
4、te(accounts); MyAccount account=new MyAccount(); for(int i=0;i 4.2.4计算结果界面代码以下: % List list=(List)request.getAttribute(result); for(int i=0;i 4.3Java方法设计4.3.1Servlet类控制增删改操作servlet类代码设计以下:package com.controller;import com.dao.*;import com.domain.MyAccount;import java.io.IOException;import java.io.Pr
5、intWriter;import java.util.List;import javax.servlet.RequestDispatcher;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class AccountController extends HttpServlet protected v
6、oid 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); swi
7、tch(arg) /依据每个form传输不一样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
8、 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(resul
9、t,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.fi
10、ndAllAccount(); 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.setCharacterE
11、ncoding(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 my
12、Account=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(reque
13、st,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 account
14、Dao=new AccountDao(); try accountDao.deleteSomeAccount(myAccount); catch(Exception e) e.printStackTrace(); this.findAllAccount(request, response); 密码验证Servlet类代码以下:import java.io.IOException;import java.io.PrintWriter;import javax.servlet.RequestDispatcher;import javax.servlet.ServletException;impor
15、t javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import sunyang.domain.User;import sunyang.service.UserService;public class LoginServlet extends HttpServlet public void doGet(HttpServletR
16、equest 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 Use
17、r(); 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(r
18、eq,resp); 4.3.2Dao类密码验证Dao类代码设计以下:package sunyang.service;import sunyang.domain.User;public class UserService public static boolean CheckLogin(User user) if(user.getUsername().equals(lb)&user.getPassword().equals(123) return true; return false; 帐务添加查询计算Dao类代码设计以下:package com.dao;import java.sql.Conn
19、ection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import java.util.List;import com.domain.MyAccount;import com.util.DBCon;public class AccountDao private Connection conn; public List findAllAccount() /查询全部帐务信息 conn=DBCon.getCon
20、nection(); 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.se
21、tCostmoney(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 saveAllAccoun
22、t(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.ge
23、tRecord(); 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 myaccou
24、nt 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(); /
25、计算帐目标和 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();
26、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(inc
27、ometotal); account.setCostmoney(costtotal); list2.add(account); return list2; catch(SQLException e) e.printStackTrace(); return list2; 4.3.3domain类密码验证代买设计以下:package sunyang.domain;public class User private String username; private String password;public String getUsername() return username;public v
28、oid setUsername(String username) this.username = username;public String getPassword() return password;public void setPassword(String password) this.password = password;帐务信息代码设计以下:package com.domain;public class MyAccount private Integer id;private Double incomemoney;private Double costmoney;private
29、String record;private String time;public String getTime() return time;public void setTime(String time) this.time = time;public Integer getId() return id;public void setId(Integer id) this.id = id;public Double getIncomemoney() return incomemoney;public void setIncomemoney(Double incomemoney) this.in
30、comemoney = incomemoney;public Double getCostmoney() return costmoney;public void setCostmoney(Double costmoney) this.costmoney = costmoney;public String getRecord() return record;public void setRecord(String record) this.record = record;4.3.4数据库连接类数据库连接代码以下:package com.util;import java.sql.Connecti
31、on;import java.sql.DriverManager;import java.sql.SQLException;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.SQLS
32、erverDriver);catch(ClassNotFoundException e)e.printStackTrace();tryconn=DriverManager.getConnection(url, user, psw);conn.setAutoCommit(false);return conn;catch(SQLException e)e.printStackTrace();return null;5 总结和展望经过此次课程设计自己JavaWeb编程加深了了解,对MVC模型工作原理和工作过程有了更深刻了解,对struts2模型及其工作过程也有了比以前更深认识,对于怎样配置web.xml和struts.xml文件也加深了记忆,Filterdispatcher过滤器作用自己也深入加深了印象。最关键是自己在这次课程设计中培养了自己独立觉问题能力和处理问题耐心。比如自己在计算收入和支出帐务和时候,刚开始自己所写算法之不能正确