轉(zhuǎn)賬系統(tǒng)設(shè)計(jì)——Servlet技術(shù)JavaBean技術(shù)Jsp技術(shù)_第1頁
轉(zhuǎn)賬系統(tǒng)設(shè)計(jì)——Servlet技術(shù)JavaBean技術(shù)Jsp技術(shù)_第2頁
轉(zhuǎn)賬系統(tǒng)設(shè)計(jì)——Servlet技術(shù)JavaBean技術(shù)Jsp技術(shù)_第3頁
轉(zhuǎn)賬系統(tǒng)設(shè)計(jì)——Servlet技術(shù)JavaBean技術(shù)Jsp技術(shù)_第4頁
轉(zhuǎn)賬系統(tǒng)設(shè)計(jì)——Servlet技術(shù)JavaBean技術(shù)Jsp技術(shù)_第5頁
已閱讀5頁,還剩102頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、 轉(zhuǎn)賬系統(tǒng)設(shè)計(jì) Servlet技術(shù) JavaBean技術(shù) Jsp技術(shù) Java web 轉(zhuǎn)賬系統(tǒng)設(shè)計(jì)完整代碼 1,登陸界面:login.jsp代碼如下: base href= My JSP login.jsp starting page !- 歡迎進(jìn)入賬戶登陸界面! 賬戶名: 密碼: 2,注冊(cè)界面amountAdd.jsp代碼如下: base href= My JSP amountAdd.jsp starting page !- 注 冊(cè) 新 賬 戶 界 面 賬戶名: 密碼: 單擊注冊(cè)按鈕單擊添加賬戶資金:進(jìn)入增加資金界面增加資金界面amountMoneyAdd.jsp base href= M

2、y JSP amountMoneyAdd.jsp starting page !- 增 加 資 金 界 面 賬戶名: 增加資金: 密碼: 再次注冊(cè)新賬戶:如有再次注冊(cè)則注冊(cè)失敗:添加資金20000:查詢?nèi)抠~戶:核心業(yè)務(wù)轉(zhuǎn)賬功能:4 刪除界面 amountDelete.jsp如果沒有賬戶名,則刪除失??!代碼如下: base href= My JSP amountDelete.jsp starting page !- 賬戶刪除界面 賬戶名: 密碼: 再次登錄賬戶 幽居望竹清風(fēng) 賬戶不存在:業(yè)務(wù)Servlet類如下:Login.Java 登錄驗(yàn)證數(shù)據(jù)庫核心類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);/沒有設(shè)置編碼的話,中文登陸不了 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();/得到一個(gè)會(huì)話 session.setAttribute(amountName, amountName);/會(huì)話傳遞參數(shù) request.getRequestDispatcher(/servlet/amountData).forward(request, response); /頁amountAdd 賬戶增加核心業(yè)務(wù)類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();/查找賬戶名是否存在數(shù)據(jù)庫中,存在則重新輸入賬戶名amount am1=amountDao.login(amountName,pwd);/調(diào)用持久類中的方法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( 賬戶數(shù)據(jù)界面);out.println( );out.print();out.print(賬戶數(shù)據(jù));out.print(賬戶名金錢);for(amount am:amounts) out.print(+am.getName()+am.getMoney

15、()+);out.println( );out.print(刪除 );/*out.print(轉(zhuǎn)賬 );*/out.print(返回登錄界面 );out.print(轉(zhuǎn)賬界面 );out.print(index.jsp );out.print(查詢?nèi)抠~戶 );out.print(刪除賬戶 );out.print(增加賬戶資金 );out.print(注冊(cè) );out.println( );out.println();out.flush();out.close();amountChange 轉(zhuǎn)賬系統(tǒng)轉(zhuǎn)賬核心類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(轉(zhuǎn)賬前賬戶有資金:amounts1.ge

20、t(0).getMoney()=+amounts1.get(0).getMoney();if(amounts1.get(0).getMoney()=0) amountDao.amountChange(aimAmountName,amountName, amountMoney);/轉(zhuǎn)賬業(yè)務(wù)/轉(zhuǎn)賬業(yè)務(wù)out.print(賬戶+amountName+沒有足夠資金!不能轉(zhuǎn)賬!);elseamountDao.amountChange(amountName, aimAmountName, amountMoney);/轉(zhuǎn)賬業(yè)務(wù) List amounts=amountDao.getAmountView();/

21、*out.println(集合對(duì)象是否為空:+amounts.isEmpty();*/out.println();out.println();out.println( 賬戶數(shù)據(jù)界面);out.println( );out.print();out.print(賬戶數(shù)據(jù));out.print(賬戶名金錢);for(amount am:amounts)/集合循環(huán)調(diào)用if(am.getMoney()=0)am.setMoney(0); out.print(+am.getName()+am.getMoney()+); out.println( );out.print(刪除 );/*out.print(轉(zhuǎn)

22、賬 );*/out.print(返回登錄界面 );out.print(轉(zhuǎn)賬界面 );out.print(index.jsp );out.print(查詢?nèi)抠~戶 );out.print(amountName+amountName);out.print(aimAmountName+aimAmountName);out.print(amountMoney=+amountMoney);out.println( );out.println();out.flush();out.close(); 單賬戶數(shù)據(jù)顯示類: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();/得到會(huì)話ID,會(huì)話Id是系統(tǒng)分配的唯一標(biāo)識(shí) String amountName=(String) session.getAttribute(amountName);/必須強(qiáng)制轉(zhuǎn)換字符型; if(amountName=null|.equals(amountName) response.sendRedirect(index.jsp);/重定向登陸界面 else/* am

28、ountName=amountName.substring(0,5); /*/Listamounts=amountDao.getAmountData(amountName);/調(diào)用持久類中的方法 request.setCharacterEncoding(UTF-8); response.setCharacterEncoding(UTF-8); response.setContentType(text/html);PrintWriter out = response.getWriter();/*out.println(集合對(duì)象是否為空:+amounts.isEmpty();*/out.print

29、ln();out.println();out.println( 賬戶數(shù)據(jù)查詢界面);out.println( );out.print();out.print(賬戶數(shù)據(jù));out.print(賬戶名金錢);for(amount am:amounts) out.print(+am.getName()+am.getMoney()+); out.println( );/*out.print(刪除 );*/*out.print(轉(zhuǎn)賬 );*/out.print(返回登錄 );out.print(轉(zhuǎn)賬 );out.print(添加賬戶資金 );out.print(刪除賬戶資金 );out.print(添加

30、賬戶 );out.print(刪除賬戶 );out.print(查詢?nèi)抠~戶 );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( 賬戶數(shù)據(jù)界面);out.println( );out.print();out.print(賬戶數(shù)據(jù));out.print(賬戶名金錢);for(amount am:amounts) out.print(+am.getName()+am.getMoney()+);out.println( );/*out.print(刪除 );*/*out.print(轉(zhuǎn)賬 );*/out.print(返回登錄界面 );out.print(轉(zhuǎn)賬界面 );out.print(

37、注冊(cè) );out.print(查詢?nèi)抠~戶 );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( 賬戶數(shù)據(jù)查詢界面);out.println( );out.print();out.print(賬戶數(shù)據(jù));out.print(賬戶名金錢);for(amount am:amounts)/集合循環(huán)調(diào)用out.print(+am.getName()+am.getMoney()+);out.println( );out.print(刪除 );/*out.pr

44、int(轉(zhuǎn)賬 );*/out.print(返回登錄界面 );out.print(轉(zhuǎn)賬界面 );out.print(index.jsp );out.print(返回 );out.print(注冊(cè) );out.print(查詢?nèi)抠~戶 );out.println( );out.println();out.flush();out.close();賬戶數(shù)據(jù)全部顯示類: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( 賬戶數(shù)據(jù)查詢界面);out.println( );out.print();out.print(賬戶數(shù)據(jù));out.print(賬戶名金錢);for(amount a

50、m:amounts)/集合循環(huán)調(diào)用out.print(+am.getName()+am.getMoney()+);out.println( );/*out.print(刪除 );*/*out.print(轉(zhuǎn)賬 );*/out.print(返回登錄界面 );out.print(轉(zhuǎn)賬界面 );out.print(index.jsp );out.print(刪除賬戶 );out.print(增加賬戶資金 );out.print(注冊(cè) );out.print(查詢?nèi)抠~戶 );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;數(shù)據(jù)庫持久核心業(yè)務(wù)類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 /檢查賬戶是否存在,參數(shù)為賬戶名,密碼public static amount login(String amountName,String amountPwd)amount am=null; String sql=select * from 賬戶表 where 賬戶=? and 密碼=?;Connection conn=null;/連接數(shù)據(jù)庫接口PreparedStatement pre=null;/預(yù)處理接口ResultSet rs=null;/結(jié)果集接口try conn=connectionFactory.getConnection();/Connection對(duì)象為Sql借口

54、pre=conn.prepareStatement(sql);pre.setString(1, amountName);pre.setString(2, amountPwd);/* rs=pre.executeQuery();/返回結(jié)果集對(duì)象* /*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;/連接數(shù)據(jù)庫接口PreparedStatement pre=null;/預(yù)處理接口ResultSet rs=null;/結(jié)果集接口try conn=connectionFactory.getConnection();/Connection對(duì)象為

56、Sql借口pre=conn.prepareStatement(sql);pre.setString(1, amountName);/*pre.setString(2, amountPwd);*/* rs=pre.executeQuery();/返回結(jié)果集對(duì)象* /*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;/顯示一種賬戶名的數(shù)據(jù),而不是全部數(shù)據(jù)public static List getAmountData(String amountName)Connection conn=null;/連接數(shù)據(jù)庫接口PreparedStatement pre=null;/預(yù)處理接口ResultSet rs=null;/結(jié)果集接口 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()/顯示賬戶名的數(shù)據(jù),是全部數(shù)據(jù)Connection conn=null;/連接數(shù)據(jù)庫接口PreparedStatement pre=null;/預(yù)處理接口ResultSet rs=null;/結(jié)果集接口 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等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論