![轉賬系統(tǒng)設計——Servlet技術JavaBean技術Jsp技術_第1頁](http://file4.renrendoc.com/view/3a110bddcf738c3925083b2f96a1d82f/3a110bddcf738c3925083b2f96a1d82f1.gif)
![轉賬系統(tǒng)設計——Servlet技術JavaBean技術Jsp技術_第2頁](http://file4.renrendoc.com/view/3a110bddcf738c3925083b2f96a1d82f/3a110bddcf738c3925083b2f96a1d82f2.gif)
![轉賬系統(tǒng)設計——Servlet技術JavaBean技術Jsp技術_第3頁](http://file4.renrendoc.com/view/3a110bddcf738c3925083b2f96a1d82f/3a110bddcf738c3925083b2f96a1d82f3.gif)
![轉賬系統(tǒng)設計——Servlet技術JavaBean技術Jsp技術_第4頁](http://file4.renrendoc.com/view/3a110bddcf738c3925083b2f96a1d82f/3a110bddcf738c3925083b2f96a1d82f4.gif)
![轉賬系統(tǒng)設計——Servlet技術JavaBean技術Jsp技術_第5頁](http://file4.renrendoc.com/view/3a110bddcf738c3925083b2f96a1d82f/3a110bddcf738c3925083b2f96a1d82f5.gif)
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、 轉賬系統(tǒng)設計 Servlet技術 JavaBean技術 Jsp技術 Java web 轉賬系統(tǒng)設計完整代碼 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 !- 增 加 資 金 界 面 賬戶名: 增加資金: 密碼: 再次注冊新賬戶:如有再次注冊則注冊失?。禾砑淤Y金20000:查詢全部賬戶:核心業(yè)務轉賬功能:4 刪除界面 amountDelete.jsp如果沒有賬戶名,則刪除失??!代碼如下: base href= My JSP amountDelete.jsp starting page !- 賬戶刪除界面 賬戶名: 密碼: 再次登錄賬戶 幽居望竹清風 賬戶不存在:業(yè)務Servlet類如下:Login.Java 登錄驗證數(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);/沒有設置編碼的話,中文登陸不了 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);/會話傳遞參數(shù) request.getRequestDispatcher(/servlet/amountData).forward(request, response); /頁amountAdd 賬戶增加核心業(yè)務類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);/調用持久類中的方法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(轉賬 );*/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 轉賬系統(tǒng)轉賬核心類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);/轉賬業(yè)務/轉賬業(yè)務out.print(賬戶+amountName+沒有足夠資金!不能轉賬!);elseamountDao.amountChange(amountName, aimAmountName, amountMoney);/轉賬業(yè)務 List amounts=amountDao.getAmountView();/
21、*out.println(集合對象是否為空:+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)調用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(); 單賬戶數(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();/得到會話ID,會話Id是系統(tǒng)分配的唯一標識 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( 賬戶數(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(轉賬 );*/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( 賬戶數(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(轉賬 );*/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( 賬戶數(shù)據(jù)查詢界面);out.println( );out.print();out.print(賬戶數(shù)據(jù));out.print(賬戶名金錢);for(amount am:amounts)/集合循環(huán)調用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();賬戶數(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)調用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;數(shù)據(jù)庫持久核心業(yè)務類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;/預處理接口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;/連接數(shù)據(jù)庫接口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;/顯示一種賬戶名的數(shù)據(jù),而不是全部數(shù)據(jù)public static List getAmountData(String amountName)Connection conn=null;/連接數(shù)據(jù)庫接口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()/顯示賬戶名的數(shù)據(jù),是全部數(shù)據(jù)Connection conn=null;/連接數(shù)據(jù)庫接口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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度廣告活動策劃與執(zhí)行代理合同范本
- 2025年度中小企業(yè)信用貸款合同范本及證明書格式
- 2025年度海運集裝箱清潔與消毒服務合同
- 2025年度糧食行業(yè)市場拓展與品牌推廣合同
- 2025年度家暴離婚財產(chǎn)分割專項法律服務合同
- 金華浙江金華蘭溪市人民政府辦公室招聘勞務派遣工作人員筆試歷年參考題庫附帶答案詳解
- 貴州2025年貴州開放大學(貴州職業(yè)技術學院)招聘41人筆試歷年參考題庫附帶答案詳解
- 衢州浙江衢州江山市峽口中心幼兒園招聘幼兒園專任教師筆試歷年參考題庫附帶答案詳解
- 珠海廣東珠海市澳深度合作區(qū)頌琴小學招聘臨聘專任教師7人筆試歷年參考題庫附帶答案詳解
- 湖南2025年湖南農(nóng)業(yè)大學-岳麓山實驗室博士后招聘筆試歷年參考題庫附帶答案詳解
- 【政治】法律保障生活課件-+2024-2025學年統(tǒng)編版道德與法治七年級下冊
- 四川政采評審專家入庫考試基礎題復習試題
- 智研咨詢-2025年中國生鮮農(nóng)產(chǎn)品行業(yè)市場全景調查、投資策略研究報告
- 車輛采購論證方案
- 尼康D7000簡體中文說明書
- 員工賠償金保密協(xié)議書(2篇)
- 2023年貴州省公務員錄用考試《行測》真題及答案解析
- 中華人民共和國保守國家秘密法實施條例
- 體育賽事招商服務收費方案
- 2025年高考數(shù)學總復習:集合與常用邏輯用語(教師卷)
- 肌力分級護理課件
評論
0/150
提交評論