构建于J2EEWebServlet组件技术的控制层.docx_第1页
构建于J2EEWebServlet组件技术的控制层.docx_第2页
构建于J2EEWebServlet组件技术的控制层.docx_第3页
构建于J2EEWebServlet组件技术的控制层.docx_第4页
构建于J2EEWebServlet组件技术的控制层.docx_第5页
已阅读5页,还剩29页未读 继续免费阅读

下载本文档

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

文档简介

基于Struts+Spring+JDBC架构的课程设计实训教学示例项目网上银行账户管理系统构建基于J2EE Web Servlet组件技术的控制层杨教授大学堂 精心创作的优秀程序员 职业提升必读系列资料 基于Struts+Spring+JDBC架构的课程设计实训教学示例项目网上银行账户管理系统构建基于J2EE Web Servlet组件技术的控制层(第4/4部分) 1.1.1 构建控制层中的帐户信息管理的Servlet组件 1、AccountInfoManageServlet (1)包名称为com.px1987.webbank.servlet,并且继承于HttpServlet类 (2)设置该URL-Pattern为/accountInfoManage.action 杨教授大学堂,版权所有,盗版必究。 1/24页 杨教授大学堂 精心创作的优秀程序员 职业提升必读系列资料 (3)编程该AccountInfoManageServlet类 package com.px1987.webbank.servlet; import java.io.IOException; import java.util.ArrayList; import java.util.Date; import javax.servlet.RequestDispatcher; 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 mons.validator.GenericValidator; import org.springframework.context.ApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; 杨教授大学堂,版权所有,盗版必究。 2/24页 杨教授大学堂 精心创作的优秀程序员 职业提升必读系列资料 import com.px1987.webbank.actionform.AccountInfoActionForm; import com.px1987.webbank.config.TargetPageNameConfig; import com.px1987.webbank.constant.WebBankAllConstants; import com.px1987.webbank.exception.WebBankException; import com.px1987.webbank.model.UserInfoManageImpleFacade; import com.px1987.webbank.model.vo.AccountInfoVO; import com.px1987.webbank.model.vo.PageStateVO_Prototype; import com.px1987.webbank.model.vo.UserInfoVO; import com.px1987.webbank.util.MD5JavaBean; public class AccountInfoManageServlet extends HttpServlet private static final long serialVersionUID = -7697781505332777183L; String forwardShowWebAppError=null; String showWebAppErrorAndReturn=null; String forwardShowInfoAndGotoTarget=null; ApplicationContext applicationContext=null; public AccountInfoManageServlet() super(); public void destroy() super.destroy(); public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException /*下面是获得请求的类型并相应地跳转到目标处理方法中* String action=request.getParameter(action); if(action.equals(forwardTargetPage_ShowMeAccount) forwardTargetPage_ShowMeAccount(request, response); else if(action.equals(forwardTargetPageUserID_newAccountInfo) forwardTargetPageUserID_newAccountInfo(request, response); 杨教授大学堂,版权所有,盗版必究。 3/24页 杨教授大学堂 精心创作的优秀程序员 职业提升必读系列资料 else if(action.equals(forwardTargetPageUserID_getOutSomeMoney) forwardTargetPageUserID_getOutSomeMoney(request, response); else if(action.equals(forwardTargetPageUserID_transmitAccount) forwardTargetPageUserID_transmitAccount(request, response); public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException AccountInfoActionForm oneAccountInfo=doGetAccountInfoFormData(request); /*下面是获得请求的类型并相应地跳转到目标处理方法中* if(oneAccountInfo.getAction().equals(doAddNewAccountInfo) forwardDoAddNewAccountInfo(request, response,oneAccountInfo); if(oneAccountInfo.getAction().equals(doGetOutMoney) forwardDoGetOutMoney(request, response,oneAccountInfo); if(oneAccountInfo.getAction().equals(doTransmitAccount) forwardDoTransmitAccount(request, response,oneAccountInfo); public void forwardDoTransmitAccount(HttpServletRequest request, HttpServletResponse response, AccountInfoActionForm oneAccountInfo) throws ServletException, IOException boolean okOrNot=false; UserInfoManageImpleFacade oneUserInfoManageImpleFacade=null; String userID=oneAccountInfo.getUserID(); String outPutAccountID=oneAccountInfo.getOutPutAccountID(); String inPutAccountID=oneAccountInfo.getInPutAccountID(); String balance=oneAccountInfo.getBalance(); 杨教授大学堂,版权所有,盗版必究。 4/24页 杨教授大学堂 精心创作的优秀程序员 职业提升必读系列资料 String userName=oneAccountInfo.getUserName(); /下面识别转帐金额是否小于帐户内的存款 try /没有将J2EE Web与Spring相互整合之前的实现方法 / oneUserInfoManageImpleFacade=new UserInfoManageImpleFacade(); applicationContext= WebApplicationContextUtils.getWebApplicationContext(this.getServletContext(); oneUserInfoManageImpleFacade=(UserInfoManageImpleFacade)applicationContext.getBean(oneUserInfoManageImpleFacade); okOrNot=oneUserInfoManageImpleFacade.doCheckBalanceAmountValue(balance, outPutAccountID); catch (WebBankException e) request.setAttribute(errorText, e.getMessage(); rwardShowWebAppError= TargetPageNameConfig.getProperty(forwardShowWebAppError); RequestDispatcher oneRequestDispatcher= request.getRequestDispatcher(forwardShowWebAppError); oneRequestDispatcher.forward(request, response); return; if(!okOrNot) request.setAttribute(targetURLPage, /pageForwordAction.action?action=forwardTransmitAccount); request.setAttribute(showInfoText,userName+您好!您的转出帐户:+outPutAccountID+中的资金不足够); forwardShowInfoAndGotoTarget= TargetPageNameConfig.getProperty(forwardShowInfoAndGotoTarget); RequestDispatcher oneRequestDispatcher= request.getRequestDispatcher(forwardShowInfoAndGotoTarget); 杨教授大学堂,版权所有,盗版必究。 5/24页 杨教授大学堂 精心创作的优秀程序员 职业提升必读系列资料 oneRequestDispatcher.forward(request, response); return; /下面的代码是具体实现转帐 try okOrNot=oneUserInfoManageImpleFacade.doTransferAccount(outPutAccountID, inPutAccountID, Float.parseFloat(balance); catch (WebBankException e) request.setAttribute(errorText, e.getMessage(); forwardShowWebAppError= TargetPageNameConfig.getProperty(forwardShowWebAppError); RequestDispatcher oneRequestDispatcher= request.getRequestDispatcher(forwardShowWebAppError); oneRequestDispatcher.forward(request, response); return; if(!okOrNot) request.setAttribute(errorText, userName+您好!您对转出帐户:+outPutAccountID+的转帐行为没有成功); forwardShowWebAppError= TargetPageNameConfig.getProperty(forwardShowWebAppError); RequestDispatcher oneRequestDispatcher= request.getRequestDispatcher(forwardShowWebAppError); oneRequestDispatcher.forward(request, response); return; /一旦转帐成功,将根据该用户的ID获得其各个帐户信息 ArrayList onePageAccountInfoVOArrayList=null; PageStateVO_Prototype onePageStateVO_Prototype=null; 杨教授大学堂,版权所有,盗版必究。 6/24页 杨教授大学堂 精心创作的优秀程序员 职业提升必读系列资料 String firstPageNumber=1; try onePageStateVO_Prototype=new PageStateVO_Prototype(); onePageStateVO_Prototype.setThisPageNumber(Integer.parseInt(firstPageNumber); /根据该用户的ID获得其各个帐户信息(但只取出第一页的数据) onePageStateVO_Prototype.setPageSize(WebBankAllConstants.webServiceManage_pageSize); onePageAccountInfoVOArrayList=oneUserInfoManageImpleFacade.doGetOnePageAccountInfoByUserID(onePageStateVO_Prototype,userID); catch(WebBankException e) request.setAttribute(errorText, e.getMessage(); forwardShowWebAppError= TargetPageNameConfig.getProperty(forwardShowWebAppError); RequestDispatcher oneRequestDispatcher= request.getRequestDispatcher(forwardShowWebAppError); oneRequestDispatcher.forward(request, response); return; request.setAttribute(onePageAccountInfoVOArrayList,onePageAccountInfoVOArrayList); request.setAttribute(onePageStateVO_Prototype,onePageStateVO_Prototype); request.setAttribute(currentPageNumber,new Integer(onePageStateVO_Prototype.getThisPageNumber().toString(); String forwardShowMeAccountInfo= TargetPageNameConfig.getProperty(forwardShowMeAccountInfo); RequestDispatcher oneRequestDispatcher= request.getRequestDispatcher(forwardShowMeAccountInfo); oneRequestDispatcher.forward(request, response); return; /跳转到显示其各个帐户信息的页面 杨教授大学堂,版权所有,盗版必究。 7/24页 杨教授大学堂 精心创作的优秀程序员 职业提升必读系列资料 /* 下面的各个方法是针对 用户的帐户进行分页控制的各个方法* public void forwardTargetPageUserID_getOutSomeMoney(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException UserInfoManageImpleFacade oneUserInfoManageImpleFacade=null; /获得用户所输入的页数 String targetPageNumber=request.getParameter(targetPage); HttpSession session=request.getSession(); /获得保存在session中的用户信息(会话跟踪) UserInfoVO oneUserInfoVOInSession= (UserInfoVO)session.getAttribute(oneUserInfoVO); ArrayList onePageAccountInfoVOArrayList=null; PageStateVO_Prototype onePageStateVO_Prototype=null; try onePageStateVO_Prototype=new PageStateVO_Prototype(); onePageStateVO_Prototype.setThisPageNumber(Integer.parseInt(targetPageNumber); onePageStateVO_Prototype.setPageSize(WebBankAllConstants.webServiceManage_pageSize); /没有将J2EE Web与Spring相互整合之前的实现方法 / oneUserInfoManageImpleFacade=new UserInfoManageImpleFacade(); applicationContext= WebApplicationContextUtils.getWebApplicationContext(this.getServletContext(); oneUserInfoManageImpleFacade=(UserInfoManageImpleFacade)applicationContext.getBean(oneUserInfoManageImpleFacade); onePageAccountInfoVOArrayList=oneUserInfoManageImpleFacade.doGetOnePageAccountInfoByUserID(onePageStateVO_Prototype,oneUserInfoVOInSession.getId(); catch(WebBankException e) request.setAttribute(errorText, e.getMessage(); rwardShowWebAppError= TargetPageNameConfig.getProperty(forwardShowWebAppError); RequestDispatcher oneRequestDispatcher= 杨教授大学堂,版权所有,盗版必究。 8/24页 杨教授大学堂 精心创作的优秀程序员 职业提升必读系列资料 request.getRequestDispatcher(forwardShowWebAppError); oneRequestDispatcher.forward(request, response); return; request.setAttribute(onePageAccountInfoVOArrayList,onePageAccountInfoVOArrayList); request.setAttribute(onePageStateVO_Prototype,onePageStateVO_Prototype); request.setAttribute(currentPageNumber,new Integer(onePageStateVO_Prototype.getThisPageNumber().toString(); String forwardGetOutSomeMoney= TargetPageNameConfig.getProperty(forwardGetOutSomeMoney); RequestDispatcher oneRequestDispatcher= request.getRequestDispatcher(forwardGetOutSomeMoney); oneRequestDispatcher.forward(request, response); return; /跳转到继续取钱信息的页面 public void forwardDoGetOutMoney(HttpServletRequest request, HttpServletResponse response,AccountInfoActionForm oneAccountInfo) throws ServletException, IOException boolean okOrNot=false; UserInfoManageImpleFacade oneUserInfoManageImpleFacade=null; String userID=oneAccountInfo.getUserID(); String accountInfo_ActionType=oneAccountInfo.getAccountInfo_ActionType(); String accountID=oneAccountInfo.getAccountID(); String idCard=oneAccountInfo.getIdCard(); String balance=oneAccountInfo.getBalance(); String userPassWord=oneAccountInfo.getUserPassWord(); /* try /没有将J2EE Web与Spring相互整合之前的实现方法 oneUserInfoManageImpleFacade=new UserInfoManageImpleFacade(); 杨教授大学堂,版权所有,盗版必究。 9/24页 杨教授大学堂 精心创作的优秀程序员 职业提升必读系列资料 catch (WebBankException e) request.setAttribute(errorText, e.getMessage(); rwardShowWebAppError= TargetPageNameConfig.getProperty(forwardShowWebAppError); RequestDispatcher oneRequestDispatcher= request.getRequestDispatcher(forwardShowWebAppError); oneRequestDispatcher.forward(request, response); return; */ applicationContext= WebApplicationContextUtils.getWebApplicationContext(this.getServletContext(); oneUserInfoManageImpleFacade= (UserInfoManageImpleFacade)applicationContext.getBean(oneUserInfoManageImpleFacade); switch(Integer.parseInt(accountInfo_ActionType) case 1: /取出款额 try okOrNot=oneUserInfoManageImpleFacade.doGetOutSomeMoneyToOneAccount(accountID, Float.parseFloat(balance); catch(WebBankException e) request.setAttribute(errorText, e.getMessage(); ardShowWebAppError= TargetPageNameConfig.getProperty(forwardShowWebAppError); RequestDispatcher oneRequestDispatcher= request.getRequestDispatcher(forwardShowWebAppError); oneRequestDispatcher.forward(request, response); return; if(!okOrNot) 杨教授大学堂,版权所有,盗版必究。 10/24页 杨教授大学堂 精心创作的优秀程序员 职业提升必读系列资料 request.setAttribute(errorText, 您对帐户:+accountID+的取款行为没有成功,请与管理员联系); WebAppErrorAndReturn= TargetPageNameConfig.getProperty(showWebAppErrorAndReturn); RequestDispatcher oneRequestDispatcher= request.getRequestDispatcher(showWebAppErrorAndReturn); oneRequestDispatcher.forward(request, response); return; break; case 2: /销毁帐户 try okOrNot=oneUserInfoManageImpleFacade.doDeleteOneAccountInfo(accountID); catch(WebBankException e) request.setAttribute(errorText, e.getMessage(); wardShowWebAppError= TargetPageNameConfig.getProperty(forwardShowWebAppError); RequestDispatcher oneRequestDispatcher= request.getRequestDispatcher(forwardShowWebAppError); oneRequestDispatcher.forward(request, response); return; if(!okOrNot) request.setAttribute(errorText, 您对帐户:+accountID+的销户行为没有成功,请与管理员联系); WebAppErrorAndReturn= TargetPageNameConfig.getProperty(showWebAppErrorAndReturn); RequestDispatcher oneRequestDispatcher= request.getRequestDispatcher(showWebAppErrorAndReturn); 杨教授大学堂,版权所有,盗版必究。 11/24页 杨教授大学堂 精心创作的优秀程序员 职业提升必读系列资料 oneRequestDispatcher.forward(request, response); return; break; ArrayList onePageAccountInfoVOArrayList=null; PageStateVO_Prototype onePageStateVO_Prototype=null; String firstPageNumber=1; try onePageStateVO_Prototype=new PageStateVO_Prototype(); onePageStateVO_Prototype.setThisPageNumber(Integer.parseInt(firstPageNumber); /根据该用户的ID获得其各个帐户信息(但只取出第一页的数据) onePageStateVO_Prototype.setPageSize(WebBankAllConstants.webServiceManage_pageSize); onePageAccountInfoVOArrayList=oneUserInfoManageImpleFacade.doGetOnePageAccountInfoByUserID(onePageStateVO_Prototype,userID); catch(WebBankException e) request.setAttribute(errorText, e.getMessage(); rwardShowWebAppError= TargetPageNameConfig.getProperty(forwardShowWebAppError); RequestDispatcher oneRequestDispatcher= request.getRequestDispatcher(forwardShowWebAppError); oneRequestDispatcher.forward(request, response); return; request.setAttribute(onePageAccountInfoVOArrayList,onePageAccountInfoVOArrayList); request.setAttribute(onePageStateVO_Prototype,onePageStateVO_Prototype); request.setAttribute(currentPageNumber,new 杨教授大学堂,版权所有,盗版必究。 12/24页 杨教授大学堂 精心创作的优秀程序员 职业提升必读系列资料 Integer(onePageStateVO_Prototype.getThisPageNumber().toString(); String forwardShowMeAccountInfo= TargetPageNameConfig.getProperty(forwardShowMeAccountInfo); RequestDispatcher oneRequestDispatcher= request.getRequestDispatcher(forwardShowMeAccountInfo); oneRequestDispatcher.forward(request, response); return; public void forwardDoAddNewAccountInfo(HttpServletRequest request, HttpServletResponse response,AccountInfoActionForm oneAccountInfo) hrows ServletException, IOException boolean okOrNot=false; UserInfoManageImpleFacade oneUserInfoManageImpleFacade=null; String balance=oneAccountInfo.getBalance(); String idCard=oneAccountInfo.getIdCard(); String userID=oneAccountInfo.getUserID(); String userPassWord=oneAccountInfo.getUserPassWord(); String state=oneAccountInfo.getState(); int savingMonth=oneAccountInfo.getSavingMonth(); String accountID=oneAccountInfo.getAccountID(); String accountInfo_ActionType=oneAccountInfo.getAccountInfo_ActionType(); AccountInfoVO oneAccountInfoVO=null; switch(Integer.parseInt(accountInfo_ActionType) case 1: /开设帐户 oneAccountInfoVO=new AccountInfoVO(); Date oneDate=new Date(); oneAccountInfoVO.setAccountID(new Long(oneDate.getTime().toString(); oneAccountInfoVO.setPassword(new MD5JavaBean().getkeyBeanofStr(userPassWord); oneAccountInfoVO.setState(state); 杨教授大学堂,版权所有,盗版必究。 13/24页 杨教授大学堂 精心创作的优秀程序员 职业提升必读系列资料 oneAccountInfoVO.setBalance(Float.parseFloat(balance); oneAccountInfoVO.setStartTime(new java.sql.Date(oneDate.getYear(),oneDate.getMonth(),oneDate.getDate(); oneAccountInfoVO.setSavingMonth(new Integer(savingMonth); oneAccountInfoVO.setIdCard(idCard); oneAccountInfoVO.setUserID(userID); break; case 2: /追加存款 break; /* try oneUserInfoManageImpleFacade=new UserInfoManageImpleFacade(); /没有将J2EE Web与Spring相互整合之前的实现方法 catch (WebBankException e) request.setAttribute(errorText, e.getMessage(); rwardShowWebAppError= TargetPageNameConfig.getProperty(forwardShowWebAppError); RequestDispatcher oneRequestDispatcher= request.getRequestDispatcher(forwardShowWebAppError); oneRequestDispatcher.forward(request, response); return; */ plicationContext= WebApplicationContextUtils.getWebApplicationContext(this.getServletContext(); oneUserInfoManageImpleFacade=(UserInfoManageImpleFacade)applicationContext.getBean(oneUserInfoManageImpleFacade); switch(Integer.parseInt(accountInfo_ActionType) 杨教授大学堂,版权所有,盗版必究。 14/24页 杨教授大学堂 精心创作的优秀程序员 职业提升必读系列资料 case 1: try okOrNot=oneUserInfoManageImpleFacade.doCreateOneAccountInfo(oneAccountInfoVO); catch(WebBankException e) request.setAttribute(errorText, e.getMessage(); ardShowWebAppError= TargetPageNameConfig.getProperty(forwardShowWebAppError); RequestDispatcher oneRequestDispatcher= request.getRequestDispatcher(forwardShowWebAppError); oneRequestDispatcher.forward(request, response); return; if(!okOrNot) request.setAttribute(errorText, 您的开户行为没有成功,请与管理员联系); WebAppErrorAndReturn= TargetPageNameConfig.getProperty(showWebAppErrorAndReturn); RequestDispatcher oneRequestDispatcher= request.getRequestDispatcher(showWebAppErrorAndReturn); oneRequestDispatcher.forward(request, response); return; break; case 2: try okOrNot=oneUserInfoManageImpleFacade.doAddSomeMoneyToOneAccount(accountID,Float.parseFloat(balance); catch(WebBankException e) 杨教授大学堂,版权所有,盗版必究。 15/24页 杨教授大学堂 精心创作的优秀程序员 职业提升必读系列资料 request.setAttribute(errorText, e.getMessage(); ardShowWebAppError= TargetPageNameConfig.getProperty(forwardShowWebAppError); RequestDispatcher oneRequestDispatcher= reques

温馨提示

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

评论

0/150

提交评论