转账系统设计——Servlet技术JavaBean技术Jsp技术_第1页
转账系统设计——Servlet技术JavaBean技术Jsp技术_第2页
转账系统设计——Servlet技术JavaBean技术Jsp技术_第3页
转账系统设计——Servlet技术JavaBean技术Jsp技术_第4页
转账系统设计——Servlet技术JavaBean技术Jsp技术_第5页
已阅读5页,还剩102页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、 转账系统设计 Servlet技术 JavaBean技术 Jsp技术 Java web 转账系统设计完整代码 1,登陆界面:login.jsp代码如下: base href= My JSP login.jsp starting page !- 欢迎进入账户登陆界面! 账户名: 密码: 2,注册界面amountAdd.jsp代码如下: base href= My JSP amountAdd.jsp starting page !- 注 册 新 账 户 界 面 账户名: 密码: 单击注册按钮单击添加账户资金:进入增加资金界面增加资金界面amountMoneyAdd.jsp base href= M

2、y JSP amountMoneyAdd.jsp starting page !- 增 加 资 金 界 面 账户名: 增加资金: 密码: 再次注册新账户:如有再次注册则注册失败:添加资金20000:查询全部账户:核心业务转账功能:4 删除界面 amountDelete.jsp如果没有账户名,则删除失败!代码如下: base href= My JSP amountDelete.jsp starting page !- 账户删除界面 账户名: 密码: 再次登录账户 幽居望竹清风 账户不存在:业务Servlet类如下:Login.Java 登录验证数据库核心类package servlet;impo

3、rt java.io.IOException;import java.io.PrintWriter;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import pojo.amount;import dao.amountDao;publi

4、c class login extends HttpServlet /* * The doGet method of the servlet. * * This method is called when a form has its tag value method equals to get. * * param request the request send by the client to the server * param response the response send by the server to the client * throws ServletExceptio

5、n if an error occurred * throws IOException if an error occurred */public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException this.doPost(request, response);public void doPost(HttpServletRequest request, HttpServletResponse response)throws Servlet

6、Exception, IOException request.setCharacterEncoding(UTF-8); response.setCharacterEncoding(UTF-8);/没有设置编码的话,中文登陆不了 response.setContentType(text/html);PrintWriter out = response.getWriter();String amountName=request.getParameter(amountName);String amountPwd=request.getParameter(pwd);amount am=amountDa

7、o.login(amountName, amountPwd);if(am=null)response.sendRedirect(login.jsp);elseHttpSession session=request.getSession();/得到一个会话 session.setAttribute(amountName, amountName);/会话传递参数 request.getRequestDispatcher(/servlet/amountData).forward(request, response); /页amountAdd 账户增加核心业务类package servlet;impo

8、rt java.io.IOException;import java.io.PrintWriter;import java.util.ArrayList;import java.util.List;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import pojo.amount;import dao.amou

9、ntDao;public class amountAdd extends HttpServlet /* * The doGet method of the servlet. * * This method is called when a form has its tag value method equals to get. * * param request the request send by the client to the server * param response the response send by the server to the client * throws

10、ServletException if an error occurred * throws IOException if an error occurred */public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException this.doPost(request, response);/* * The doPost method of the servlet. * * This method is called when a for

11、m has its tag value method equals to post. * * param request the request send by the client to the server * param response the response send by the server to the client * throws ServletException if an error occurred * throws IOException if an error occurred */public void doPost(HttpServletRequest re

12、quest, HttpServletResponse response)throws ServletException, IOException request.setCharacterEncoding(UTF-8); response.setCharacterEncoding(UTF-8); response.setContentType(text/html);PrintWriter out = response.getWriter();String amountName=request.getParameter(amountName);String pwd=request.getParam

13、eter(pwd);List amounts=new ArrayList();/查找账户名是否存在数据库中,存在则重新输入账户名amount am1=amountDao.login(amountName,pwd);/调用持久类中的方法amount am2=amountDao.login(amountName);/*System.out.print(amounts.get(1).getName()*+amounts.get(0).getName();*/if(am1!=null|.equals(amountName)|am2!=null)response.sendRedirect(./amoun

14、tAddFailure.jsp);/重定向else/*amounts2.clear();*/ amountDao.amountInsert(amountName, pwd); amounts=amountDao.getAmountData(amountName); out.println();out.println();out.println( 账户数据界面);out.println( );out.print();out.print(账户数据);out.print(账户名金钱);for(amount am:amounts) out.print(+am.getName()+am.getMoney

15、()+);out.println( );out.print(删除 );/*out.print(转账 );*/out.print(返回登录界面 );out.print(转账界面 );out.print(index.jsp );out.print(查询全部账户 );out.print(删除账户 );out.print(增加账户资金 );out.print(注册 );out.println( );out.println();out.flush();out.close();amountChange 转账系统转账核心类package servlet;import java.io.IOException;

16、import java.io.PrintWriter;import java.util.List;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import pojo.amount;import dao.amountDao;public class amountChange extends HttpServle

17、t public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException this.doPost(request, response);public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException String amountName=request.getParameter(amo

18、untName); String aimAmountName=request.getParameter(aimAmountName); String amountMoney =request.getParameter(money); request.setCharacterEncoding(UTF-8); response.setCharacterEncoding(UTF-8); response.setContentType(text/html); PrintWriter out = response.getWriter(); if(amountMoney.isEmpty()|amountN

19、ame.isEmpty()|aimAmountName.isEmpty() response.sendRedirect(./amountChange.jsp); else/ List amounts=amountDao.amountChange(amountName, aimAmountName, amountMoney);/* List amounts1=amountDao.getAmountData(amountName);*/ List amounts1=amountDao.getAmountData(amountName); out.print(转账前账户有资金:amounts1.ge

20、t(0).getMoney()=+amounts1.get(0).getMoney();if(amounts1.get(0).getMoney()=0) amountDao.amountChange(aimAmountName,amountName, amountMoney);/转账业务/转账业务out.print(账户+amountName+没有足够资金!不能转账!);elseamountDao.amountChange(amountName, aimAmountName, amountMoney);/转账业务 List amounts=amountDao.getAmountView();/

21、*out.println(集合对象是否为空:+amounts.isEmpty();*/out.println();out.println();out.println( 账户数据界面);out.println( );out.print();out.print(账户数据);out.print(账户名金钱);for(amount am:amounts)/集合循环调用if(am.getMoney()=0)am.setMoney(0); out.print(+am.getName()+am.getMoney()+); out.println( );out.print(删除 );/*out.print(转

22、账 );*/out.print(返回登录界面 );out.print(转账界面 );out.print(index.jsp );out.print(查询全部账户 );out.print(amountName+amountName);out.print(aimAmountName+aimAmountName);out.print(amountMoney=+amountMoney);out.println( );out.println();out.flush();out.close(); 单账户数据显示类:amountData.Javapackage servlet;import java.io.

23、IOException;import java.io.PrintWriter;import java.util.List;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import pojo.amount;import dao.amou

24、ntDao;public class amountData extends HttpServlet /* * The doGet method of the servlet. * * This method is called when a form has its tag value method equals to get. * * param request the request send by the client to the server * param response the response send by the server to the client * throws

25、 ServletException if an error occurred * throws IOException if an error occurred */public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException this.doPost(request, response);/* * The doPost method of the servlet. * * This method is called when a fo

26、rm has its tag value method equals to post. * * param request the request send by the client to the server * param response the response send by the server to the client * throws ServletException if an error occurred * throws IOException if an error occurred */public void doPost(HttpServletRequest r

27、equest, HttpServletResponse response)throws ServletException, IOException HttpSession session=request.getSession();/得到会话ID,会话Id是系统分配的唯一标识 String amountName=(String) session.getAttribute(amountName);/必须强制转换字符型; if(amountName=null|.equals(amountName) response.sendRedirect(index.jsp);/重定向登陆界面 else/* am

28、ountName=amountName.substring(0,5); /*/Listamounts=amountDao.getAmountData(amountName);/调用持久类中的方法 request.setCharacterEncoding(UTF-8); response.setCharacterEncoding(UTF-8); response.setContentType(text/html);PrintWriter out = response.getWriter();/*out.println(集合对象是否为空:+amounts.isEmpty();*/out.print

29、ln();out.println();out.println( 账户数据查询界面);out.println( );out.print();out.print(账户数据);out.print(账户名金钱);for(amount am:amounts) out.print(+am.getName()+am.getMoney()+); out.println( );/*out.print(删除 );*/*out.print(转账 );*/out.print(返回登录 );out.print(转账 );out.print(添加账户资金 );out.print(删除账户资金 );out.print(添加

30、账户 );out.print(删除账户 );out.print(查询全部账户 );out.println( );out.println();out.flush();out.close();账户删除类:amountDelete.javapackage servlet;import java.io.IOException;import java.io.PrintWriter;import java.util.ArrayList;import java.util.List;import javax.servlet.ServletException;import javax.servlet.http.

31、HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import pojo.amount;import dao.amountDao;public class amountDelete extends HttpServlet /* * The doGet method of the servlet. * * This method is called when a form has its tag value method equals to

32、get. * * param request the request send by the client to the server * param response the response send by the server to the client * throws ServletException if an error occurred * throws IOException if an error occurred */public void doGet(HttpServletRequest request, HttpServletResponse response)thr

33、ows ServletException, IOException this.doPost(request, response);/* * The doPost method of the servlet. * * This method is called when a form has its tag value method equals to post. * * param request the request send by the client to the server * param response the response send by the server to th

34、e client * throws ServletException if an error occurred * throws IOException if an error occurred */public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException String amountName=request.getParameter(amountName);String pwd=request.getParameter(pwd)

35、;/*amount am=amountDao.login(amountName, pwd);*/List amounts=new ArrayList();amount am1=amountDao.login(amountName, pwd);if(am1=null)response.sendRedirect(./amountDeleteFailure.jsp);elseamountDao.amountDelete(amountName); amounts=amountDao.getAmountView();response.setContentType(text/html);PrintWrit

36、er out = response.getWriter();out.println();out.println();out.println( 账户数据界面);out.println( );out.print();out.print(账户数据);out.print(账户名金钱);for(amount am:amounts) out.print(+am.getName()+am.getMoney()+);out.println( );/*out.print(删除 );*/*out.print(转账 );*/out.print(返回登录界面 );out.print(转账界面 );out.print(

37、注册 );out.print(查询全部账户 );out.println( );out.println();out.flush();out.close();账户资金增加类:amountMoneyAdd.javapackage servlet;import java.io.IOException;import java.io.PrintWriter;import java.util.ArrayList;import java.util.List;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;i

38、mport javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import pojo.amount;import dao.amountDao;public class amountMoneyAdd extends HttpServlet /* * The doGet method of the servlet. * * This method is called when a form has its tag value method equals to get. * * pa

39、ram request the request send by the client to the server * param response the response send by the server to the client * throws ServletException if an error occurred * throws IOException if an error occurred */public void doGet(HttpServletRequest request, HttpServletResponse response)throws Servlet

40、Exception, IOException this.doPost(request, response);/* * The doPost method of the servlet. * * This method is called when a form has its tag value method equals to post. * * param request the request send by the client to the server * param response the response send by the server to the client *

41、throws ServletException if an error occurred * throws IOException if an error occurred */public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException String amountName=request.getParameter(amountName); String pwd=request.getParameter(pwd); String m

42、oney=request.getParameter(money); /检查账户名是否存在,不存在则不能添加资金 amount am1= amountDao.login(amountName,pwd); List amounts=new ArrayList(); if(am1=null) response.sendRedirect(./amountMoneyAdd.jsp);/重定向到添加资金界面 else amountDao.amountMoneyAdd(amountName, pwd, money);/添加账户资金 amounts= amountDao.getAmountData(amoun

43、tName); response.setContentType(text/html);PrintWriter out = response.getWriter();out.println();out.println();out.println( 账户数据查询界面);out.println( );out.print();out.print(账户数据);out.print(账户名金钱);for(amount am:amounts)/集合循环调用out.print(+am.getName()+am.getMoney()+);out.println( );out.print(删除 );/*out.pr

44、int(转账 );*/out.print(返回登录界面 );out.print(转账界面 );out.print(index.jsp );out.print(返回 );out.print(注册 );out.print(查询全部账户 );out.println( );out.println();out.flush();out.close();账户数据全部显示类:amountView.javapackage servlet;import java.io.IOException;import java.io.PrintWriter;import java.util.ArrayList;import

45、java.util.List;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import dao.amountDao;import pojo.amount;public class amountView extends HttpServlet /* * The doGet method of the servl

46、et. * * This method is called when a form has its tag value method equals to get. * * param request the request send by the client to the server * param response the response send by the server to the client * throws ServletException if an error occurred * throws IOException if an error occurred */p

47、ublic void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException this.doPost(request, response);/* * The doPost method of the servlet. * * This method is called when a form has its tag value method equals to post. * * param request the request send by th

48、e client to the server * param response the response send by the server to the client * throws ServletException if an error occurred * throws IOException if an error occurred */public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException request.se

49、tCharacterEncoding(UTF-8); response.setCharacterEncoding(UTF-8);response.setContentType(text/html);PrintWriter out = response.getWriter();List amounts=amountDao.getAmountView();out.println();out.println();out.println( 账户数据查询界面);out.println( );out.print();out.print(账户数据);out.print(账户名金钱);for(amount a

50、m:amounts)/集合循环调用out.print(+am.getName()+am.getMoney()+);out.println( );/*out.print(删除 );*/*out.print(转账 );*/out.print(返回登录界面 );out.print(转账界面 );out.print(index.jsp );out.print(删除账户 );out.print(增加账户资金 );out.print(注册 );out.print(查询全部账户 );out.println( );out.println();out.flush();out.close();Pojo类:pack

51、age pojo;public class amount private String name;private int money;private String pwd;public String getPwd() return pwd;public void setPwd(String pwd) this.pwd = pwd;public String getName() return name;public void setName(String name) = name;public int getMoney() return money;public void setMoney(in

52、t money) this.money = money;数据库持久核心业务类amountDao.java方法视图:package dao;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import java.util.List;import pojo.amount;import util.connectionFactory;public class amou

53、ntDao /检查账户是否存在,参数为账户名,密码public static amount login(String amountName,String amountPwd)amount am=null; String sql=select * from 账户表 where 账户=? and 密码=?;Connection conn=null;/连接数据库接口PreparedStatement pre=null;/预处理接口ResultSet rs=null;/结果集接口try conn=connectionFactory.getConnection();/Connection对象为Sql借口

54、pre=conn.prepareStatement(sql);pre.setString(1, amountName);pre.setString(2, amountPwd);/* rs=pre.executeQuery();/返回结果集对象* /*if(rs.next()am=new amount();am.setName(rs.getString(账户);am.setPwd(rs.getString(密码);am.setMoney(rs.getInt(金钱);mit(); catch (SQLException e) / TODO Auto-generated catch blocke.p

55、rintStackTrace();finallyCloseAll(rs,pre,conn);return am;public static amount login(String amountName)amount am=null; String sql=select * from 账户表 where 账户=?;Connection conn=null;/连接数据库接口PreparedStatement pre=null;/预处理接口ResultSet rs=null;/结果集接口try conn=connectionFactory.getConnection();/Connection对象为

56、Sql借口pre=conn.prepareStatement(sql);pre.setString(1, amountName);/*pre.setString(2, amountPwd);*/* rs=pre.executeQuery();/返回结果集对象* /*if(rs.next()am=new amount();am.setName(rs.getString(账户);/*am.setPwd(rs.getString(密码);am.setMoney(rs.getInt(金钱);*/mit(); catch (SQLException e) / TODO Auto-generated ca

57、tch blocke.printStackTrace();finallyCloseAll(rs,pre,conn);return am;/显示一种账户名的数据,而不是全部数据public static List getAmountData(String amountName)Connection conn=null;/连接数据库接口PreparedStatement pre=null;/预处理接口ResultSet rs=null;/结果集接口 String sql=select * from 账户表 where 账户=?; List amounts=new ArrayList(); amou

58、nt am=null; try conn=connectionFactory.getConnection();pre=conn.prepareStatement(sql);pre.setString(1, amountName);rs=pre.executeQuery();/*while(rs.next()am=new amount();am.setName(rs.getString(账户);am.setPwd(rs.getString(密码);am.setMoney(rs.getInt(金钱);amounts.add(am); catch (SQLException e) / TODO Au

59、to-generated catch blocke.printStackTrace();finallyCloseAll(rs,pre,conn);return amounts;public static List getAmountView()/显示账户名的数据,是全部数据Connection conn=null;/连接数据库接口PreparedStatement pre=null;/预处理接口ResultSet rs=null;/结果集接口 String sql=select * from 账户表 ; List amounts=new ArrayList(); amount am=null;

60、 try conn=connectionFactory.getConnection();pre=conn.prepareStatement(sql);rs=pre.executeQuery();while(rs.next()am=new amount();am.setName(rs.getString(账户);am.setPwd(rs.getString(密码);am.setMoney(rs.getInt(金钱);amounts.add(am); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace(

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论