javaEE 课程设计 个人财务管理系统.docx
- 文档编号:14319143
- 上传时间:2023-06-22
- 格式:DOCX
- 页数:17
- 大小:47.08KB
javaEE 课程设计 个人财务管理系统.docx
《javaEE 课程设计 个人财务管理系统.docx》由会员分享,可在线阅读,更多相关《javaEE 课程设计 个人财务管理系统.docx(17页珍藏版)》请在冰点文库上搜索。
javaEE课程设计个人财务管理系统
javaEE课程设计个人财务管理系统
件学院软
课程名称JavaEE课程设计设计题目个人财务系统专业班级软件工程学号xxxxxxxxx07姓名xxxxx指导教师姜彦吉
2011年12月
1设计时间
2011年12月12日——12月16日
2设计目的
JavaEE课程设计是对所学JavaEE与中间件课程的小结,是提高学生对所学知识综合应用能力的一种方式,是集中实践性环节之一。
要求同学们对课程中所学习到的知识综合运用,开发有一定规模的JavaWeb程序。
3设计任务
设计个人帐务管理系统,要求用户以合法的身份登录后可以对系统进行操作,用户可以查看,添加,删除和计算某段时间内帐务的收入和支出信息等。
帐务信息包括收入和支出两种,还有日期和备注。
4设计内容
4.1设计题目
个人财务管理系统
4.1.1系统功能要求
用只有拥有合法身份才能登录系统,用以合法身份登录后可以产看帐务信息、添加帐务信息、删除帐务信息、分别统计某个时间段内的收入和支出总额。
4.1.2数据库存储要求
数据的存储要求:
收入数额,支出数额,备注,日期
4.1.3数据库的设计
表—1(数据存储要求)
列名称数据类型长度
idbigint8
incomemoneymoney8
costmoneymoney8
1
recordvarchar50timevarchar8
图—1(数据库存储数据)4.1.4系统构造关系
登陆窗口
no
密码
yes
操作界面
保存查询删除计算帐目
图—2(jsp页面构造)
2
Jsp页面传递参数
调用servlet类
参数
保存方法servlet删除方法servlet查询方法servlet计算方法servlet
删除方法dao类保存方法dao类查询方法dao类计算方法dao类
图—3(Java类功能调用)
4.2Jsp页面设计
4.2.1登录界面
图—4(登录界面)
代码如下:
3
4.2.2登录成功界面
图—5(登录成功查询界面)
代码如下:
<%
Stringusername=(String)session.getAttribute("name");
if(username!
=null){%>
<%=username%>
<%}%>
arg=2"method="post"> 增加帐目明细请输入:
收入数额:
支出数额:
附加备注:
输入日期:
4
arg=1"method="post"> 查询帐目明细请点击:
删除帐目信息请如下:
arg=3"method="post"> 请输入要删除帐目的日期:
arg=4"method="post">
4.2.3查询结果界面
图—6(查询结果界面)
4.3Java方法设计
4.3.1Servlet类
5
控制增删改操作的servlet类代码设计如下:
publicclassAccountControllerextendsHttpServlet{
protectedvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)
throwsServletException,IOException{
doPost(request,response);
}
protectedvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)
throwsServletException,IOException{
intarg=Integer.parseInt(request.getParameter("arg"));
switch(arg)
{
case1:
this.findAllAccount(request,response);
break;
case2:
this.saveAllAccount(request,response);
break;
case3:
this.deleteSomeAccount(request,response);
break;
case4:
this.caculateAccount(request,response);
break;
}
}
protectedvoidcaculateAccount(HttpServletRequestrequest,
HttpServletResponseresponse)
throwsServletException,IOException
{
inta=0;
intb=0;
a=Integer.parseInt(request.getParameter("id"));
b=Integer.parseInt(request.getParameter("id"));
6
AccountDaoaccountDao=newAccountDao();
Listlist2=accountDao.caculateAccount(a,b);
request.setAttribute("result",list2);
RequestDispatcherrdt1=request.getRequestDispatcher("/Result1.jsp");
rdt1.forward(request,response);
}
publicvoidfindAllAccount(HttpServletRequestrequest,HttpServletResponseresponse)
throwsServletException,IOException
{
AccountDaoaccountDao=newAccountDao();
Listlist=accountDao.findAllAccount();
request.setAttribute("accounts",list);
RequestDispatcherrdt=request.getRequestDispatcher("/Result.jsp");
rdt.forward(request,response);
}
publicvoidsaveAllAccount(HttpServletRequestrequest,HttpServletResponse
response)
throwsServletException,IOException
{
request.setCharacterEncoding("gbk");
doubleincomemoney=0.0;
doublecostmoney=0.0;
incomemoney=Double.parseDouble(request.getParameter("incomemoney"));
costmoney=Double.parseDouble(request.getParameter("costmoney"));
Stringrecord=(String)request.getParameter("record");
Stringtime=(String)request.getParameter("time");
MyAccountmyAccount=newMyAccount();
myAccount.setIncomemoney(incomemoney);
myAccount.setCostmoney(costmoney);
7
myAccount.setRecord(record);
myAccount.setTime(time);
AccountDaoaccountDao=newAccountDao();
try{
accountDao.saveAllAccount(myAccount);
}
catch(Exceptione){
e.printStackTrace();
}
this.findAllAccount(request,response);
}
publicvoiddeleteSomeAccount(HttpServletRequestrequest,
HttpServletResponseresponse)
throwsServletException,IOException
{
request.setCharacterEncoding("gbk");
Stringtime=request.getParameter("time");
MyAccountmyAccount=newMyAccount();
myAccount.setTime(time);
AccountDaoaccountDao=newAccountDao();
try{
accountDao.deleteSomeAccount(myAccount);
}
catch(Exceptione){
e.printStackTrace();
}
this.findAllAccount(request,response);
}
}
8
密码验证的Servlet类的代码如下:
publicclassLoginServletextendsHttpServlet{
publicvoiddoGet(HttpServletRequestreq,HttpServletResponseresp)
throwsServletException,IOException{
doGet(req,resp);
}
publicvoiddoPost(HttpServletRequestreq,HttpServletResponseresp)
throwsServletException,IOException{
Stringusername=req.getParameter("username");
Stringpassword=req.getParameter("password");
Useruser=newUser();
user.setUsername(username);
user.setPassword(password);
HttpSessionsession=req.getSession();
Stringforward="";
if(UserService.CheckLogin(user))
{
forward="/Search.jsp";
session.setAttribute("name",username);
}
else
{
forward="/error.jsp";
}
RequestDispatcherrd=req.getRequestDispatcher(forward);
rd.forward(req,resp);
}
}
4.3.2Dao类
9
密码验证的Dao类代码设计如下:
publicclassUserService{
publicstaticbooleanCheckLogin(Useruser)
{
if(user.getUsername().equals("lb")&&user.getPassword().equals("123"))
{
returntrue;
}
returnfalse;
}
}
帐务添加查询计算的Dao类代码设计如下:
publicclassAccountDao{
privateConnectionconn;
publicListfindAllAccount()
{conn=DBCon.getConnection();
StringlistSQL="select*frommyaccount";
Listlist=newArrayList();
try{
PreparedStatementpsmt=conn.prepareStatement(listSQL);
ResultSetrs=psmt.executeQuery();
while(rs.next())
{
MyAccountaccount=newMyAccount();
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));
10
list.add(account);
}
mit();
returnlist;
}
catch(Exceptione){
e.printStackTrace();
}
finally
{
if(conn!
=null)
{
try{
conn.close();
}
catch(SQLExceptione){
e.printStackTrace();
}
}
}
returnlist;
}
publicbooleansaveAllAccount(MyAccountaccount)throwsException
{
conn=DBCon.getConnection();
StringlistSQL="insertintomyaccountvalues(?
?
?
?
)";
PreparedStatementpsmt=conn.prepareStatement(listSQL);
try{
psmt.setDouble(1,account.getIncomemoney());
11
psmt.setDouble(2,account.getCostmoney());
psmt.setString(3,account.getRecord());
psmt.setString(4,account.getTime());
psmt.executeUpdate();
mit();
returntrue;
}
catch(SQLExceptione){
conn.rollback();
e.printStackTrace();
}
returnfalse;
}
publicbooleandeleteSomeAccount(MyAccountaccount)throwsException
{
conn=DBCon.getConnection();
StringlistSQL="deletefrommyaccountwheretime=?
";
PreparedStatementpsmt=conn.prepareStatement(listSQL);
try{
psmt.setString(1,account.getTime());
psmt.executeUpdate();
mit();
returntrue;
}
catch(SQLExceptione){
conn.rollback();
e.printStackTrace();
}
returnfalse;
12
}
publicListcaculateAccount(intx,inty)
{
conn=DBCon.getConnection();
doubleincometotal=0.0;
doublecosttotal=0.0;
inti=0;
Listlist2=newArrayList();
try{
MyAccountaccount=newMyAccount();
for(i=x;i<=y;i++)
{
StringlistSQL1="selctincomemoneyfrommyaccountwhereid=i";
PreparedStatementpsmt1=conn.prepareStatement(listSQL1);
ResultSetrs1=psmt1.executeQuery();
psmt1.execute();
incometotal=incometotal+rs1.getDouble
(2);
StringlistSQL2="selectcostmoneyfrommyaccountwhereid=i";
PreparedStatementpsmt2=conn.prepareStatement(listSQL2);
ResultSetrs2=psmt2.executeQuery();
psmt2.execute();
costtotal=costtotal+rs2.getDouble(3);
}
mit();
account.setIncomemoney(incometotal);
account.setCostmoney(costtotal);
list2.add(account);
returnlist2;
}
13
catch(SQLExceptione){
e.printStackTrace();
}
returnlist2;}
}
4.3.3数据库连接类
数据库连接代码如下:
publicclassDBCon{
publicstaticConnectiongetConnection(){
Stringurl="jdbc:
microsoft:
sqlserver:
//localhost:
1433;databaseName=myaccountbase";
Stringuser="sa";
Stringpsw="sa";
Connectionconn=null;
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}
catch(ClassNotFoundExceptione){
e.printStackTrace();
}
try{
conn=DriverManager.getConnection(url,user,psw);
conn.setAutoCommit(false);
returnconn;
}
catch(SQLExceptione){
e.printStackTrace();
}
14
returnnull;}
}
5总结与展望
通过本次课程设计自己JavaWeb编程加深了理解,对MVC模型的工作原理和工作过程有了更深刻的理解,对struts2模型及其工作过程也有了比从前更深的认识,对于如何配置web.xml和struts.xml文件也加深了记忆,Filterdispatcher过滤器的作用自己也进一步加深了印象。
最重要的是自己在这次课程设计中培养了自己独立觉问题的能力和解决问题的耐心。
比如自己在计算收入和支出帐务的和的时候,刚开始自己所写的算法之不能正确的计算出结果,总是在返回的物理视图显示
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- javaEE 课程设计 个人财务管理系统 个人 财务管理 系统