& nbsp;
< /tr> < t r x t d colspan=3 > < tem p la te :g e t n am e= 'fo o ter7 > < /td > < /tr> < /tab le> //lo g o n js p / /T ran g đăng n h ập h ệ thông //lo g o n C o n te n t.js p .password"/> //in sertA d m in C o n ten t.jsp //T h ê m m ộ t Admin * < tr x td x b e a n :m e s s a g e key="prompt.admin.emai!" />* < trx td > < b ean :m essag e key="prompt.admin.fname" /> < /td> < /tr> < tr x td x b e a n :m e s s a g e key="prompt.admin.mname" / > < td x h tm l:te x t property="mname" / x / t d x / t r > < trx td > < b ean :m essag e key="prompt.admin.lname" / x / t d > < /td > < /tr> < bean ¡message key="prompt.admin.tel" /> < td x h tm l:te x t property="tel" /> < /td x /tr > < trx td > < b ean :m essag e key="prompt.admin.fax” / x / t d > < td x h tm l:te x t property="fax" / x / t d x / t r > < trx td > < b ean :m essag e key="prompt.admin.address" / > < td x h tm l:te x t property="address" /> < / td x /t r > < tdxh tm l:tex tarea property="description7> < tr x td x b e a n :m e s s a g e key="prompt.admin.paymentbalance" />* < /td> < trx td > < b ean :m essag e key="prompt.admin.admintype" />* < td x h tm l:select property="admintype"> Admin < html ¡option value=" 1" > ReSeller Saier < /h tm l:select> < /td x /tr> < t r x t d > < bean ¡message key="prompt.admin.agencyid" />* < td x h tm l:select property="agencyid"> < / td x /t r > < trx td > < b ean :m essag e key="prompt.admln.adminstring" />* M ộ t s o c ô n g n g h ệ p d ụ n g k iế n tr ú c M o d e l - V ie w - C o n tr o lle r 116 < td x h tm l:te x t property="adminstring" /> < / t d x / t r > < t r x t d x b e a n : message key="prompt.admin.setamntlimit" /> < / t d x / t r > < trx td > < b ean :m essag e key="prompt.admin.setcreditlimitn /> < htmltcheckbox property="setcreditlimit" value="l"/> < bean: message key="prompt.admin.maxcredit!imit" /> c T R x th co lsp an = x h r> < /th > < jnrR> < /T D x /T R > < ta b le > < trx td x b e a n :m e ssa g e key="prompt.admin.status" />* < tdxhtm l:radio property="status" value=" 17 > < /td x /tr > tr> < html :su bmit property="action" > < bean :message key= "button save"/> M o t s o c o n g n g h e d p d u n g k ie n tr u e M o d e l - V i& v - C o n t r o l l e r 118 log.debug("Cancel Button was pushed!"); return mapping.findForward("cancel"); > dbutil db = new dbutil(); Connection conn = db.cn(); try{ /* Create AdminDAO */ AdminDAO dao = DAOFactory.createAdminDAO(conn); LogonForm logonForm - (LogonForm) form; if ("load".equals(mapping.getParameter())) { return loadLogonForm(mapping, dao, logonForm); } else if ("submit".equals(mapping.getParameter())) { return doSubmitLogonForm(mapping, dao, logonForm, request, conn); > else { throw new IllegalStateExceptionQ; } >finally{ if(conn !=null) conn.close(); > > private ActionForward doSubmitLogonForm(ActionMapping mapping, AdminDAO dao, LogonForm logonForm, HttpServletRequest request, Connection conn) throws Exception{ String encriptedPassword = base.PasswordEncript(logonForm.getPassword()); Admin admin = dao.findAdminByLoginnamePassword(logonForm.getLoginname(), encriptedPassword); if (admin != null && "l".equals(admin.getStatus())){ Hashtable taskcodeList = dao.getTaskCodeList(admin.getAdminid(>); admin.setTaskcodeList(taskcodeList); request.getSession(true).setAttribute("currentAdmin", admin); }else if (admin != null && "0".equals(admin.getStatus())){ log.trace('This loginname was locked"); ActionErrors errors = new ActionErrorsO; errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.ad min.locked")); saveErrors( request, errors); return (new ActionForward(mapping.getInput())); }else{ log.trace("Login name and password not match"); ActionErrors errors = new ActionErrorsO; errors.add(ActionErrors.GLOBAL_ERROR, M o t s o c o n g n g h $ d p d u n g k ie n tr u e M o d e l - V ie w - C o n tr o lle r 119 new ActionError("error.password.mismatch")); saveErrors(request, errors); return (new ActionForward(mapping.getlnputO)); > if (mapping.getAttributeO != null) { if ("request".equals(mapping.getScope())){ log.info("Remove object form request scope"); request.removeAttribute(mapping.getAttributeO); }else{ log.info("Remove object form session scope"); request.getSession(true).removeAttribute(mapping.getAttribute()); > > return mapping.findForward("success"); > private ActionForward loadLogonForm(ActionMapping mapping, AdminDAO dao, LogonForm logonForm) { log.debug("Loading logon form"); return (new ActionForward(mapping.getlnputO)); > } //p ack ag es.actio n s.In sertA d m in A ctio n jav a //X lý việc th ê m m ộ t Admin package packages.actions; import java.sql.Connection; import java.text.SimpleDateFormat; import java util Date; import java.util.HashMap; import java util Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.DynaActionForm; import org.apache.struts.actions.LookupDispatchAction; import org.apache.struts.action.Action; import org.apache.struts.action.ActionError; M ộ t s o c ô n g n g h ệ p (lụ n g k iế n tr ú c M o d e l - V ie w - C o n tr o lle r 120 import org a pache struts.action.ActionErrors; import org apache, struts, util.MessageResources; import packages.dao.*; import packages.common.dao.*; import packages.beans.*; import packages.common.util.*; import packages.forms.*; public class InsertAdminAction extends LookupDispatchAction { private Log log = LogFactory.getLog(this.getClass().getName()); baseutil base = new baseutil(); protected Map getKeyMethodMap() { Map map = new HashMap(); map.put("button.save", "save"); return map; > public ActionForward execute(ActionMapping mapping,ActionForm form, HttpServletRequest request,HttpServletResponse response) throws Exception { Admin admin = (Admin)request.getSession(true).getAttribute("currentAdminM); if(admin!=null) log.info(#ADMIN:"+admin.getLoginname()+ 7"+base.getIP(request)+"#"); else return mapping.findForward("failure"); if(!Permission.checkPermission(TaskCode.CreateAdministrator,admin)) return mapping.findForward("notpermission"); log.info("Begin Insert Admin Action"); if (isCancelled(request)) { if (mapping.getAttribute() != null) { if ("request".equals(mapping.getScope())) request.removeAttribute(mapping.getAttribute()); else request.getSession(true).removeAttribute(mapping.getAttribute()); > log.debug("Cancel Button was pushed!"); return mapping.findForward("cancel"); > InsertAdminForm adminForm = (InsertAdminForm) form; if ("load".equals(mapping.getParameter())) return load(mapping, adminForm, request, response); return super.execute(mapping, form, request, response); M o t s o c o n g r ig h t* d p d u n g k i e n t r u e M o d e l - V ie n ’ - C o n tr o lle r 121 > private ActionForward load(ActionMapping mapping, InsertAdminForm adminForm, HttpServletRequest request, HttpServletResponse response) throws Exception{ log.info("Begin Load Insert Admin Action"); dbutil db = new dbutil(); Connection conn = db.cnQ; try { Admin currentAdmin = (Admin) request.getSession(true).getAttribute("currentAdmin"); AgentDAO dao = DAOFactory.createAgentDAO(conn); adminForm.setRemoteip(base.getIP( request)); adminForm.setRemoteuser(currentAdmin.getLoginname()); adminForm.setAgencyid(new String(currentAdmin.getAgencyidQ)); request.getSession(true).setAttribute("AgentFromInsertAdminAction", dao.listAgents(currentAdmin.getAgencyid())); > finally { conn.close(); > logJnfo("End Load Insert Admin Action"); saveToken(request); return mapping.findForward("success"); > public ActionForward save(ActionMapping mapping,ActionForm form, HttpServletRequest request,HttpServletResponse response) throws Exception { log.info("Begin Submit Insert Admin Action"); Admin admin = new Admin(); BeanUtils.copyProperties(admin, form); dbutil db = new dbutil(); Connection conn = db.cn(); try { AdminDAO dao = DAOFactory.createAdminDAO(conn); Admin newAdmin = dao.findAdminByLoginname(admin.getLoginnameO); if(newAdmin!=null){ log.trace("Loginname's already u s e r!"); ActionErrors errors - new ActionErrors(); errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.loginname.existed")); saveErrors(request, errors); M o t s o c o n g n g h $ d p d u n g k ie n tr u e M o d e l - V ie w - C o n tr o lle r 122 return (new ActionForward(mapping.getInput())); > admin.setPassword(base.PasswordEncript(admin.getPassword())); admin.setCreationdate(base.getDate()); dao.createAdmin(admin); if (mapping.getAttributeO != null) < if ("request".equals(mapping.getScope())) request.removeAttribute( mapping.getAttributeO); else > request.getSession(true).removeAttribute(mapping.getAttribute()); return mapping.findForward("success"); } finally { conn.doseQ; } > } / /s tru ts-c o n f ig.xm I < ! - = = = = = = = = = = = Validator Plugin Configs = = = = = = = = = = = = = = = = = = = = = = = M o t s o c o n g n g h e d p d u n g k ie n tr u e M o d e l - V ie w - C o n tr o lle r ... phát triể n 10 4 KÉT L U Ậ N 10 5 TÀJ LIỆU TH A M K H Ả O 10 6 PH Ụ LỤ C 10 7 Một sổ công nghệ áp dụng kiến trúc Model - View - Controller DANH MỤC... .85 11 1.5.2 Xây d ự ng thành phần M o d e l 86 M ột số công nghệ áp (lụng kiến trúc M odel - View - Controller 11 1.5.3 X ây dựng thành phận V ie w 89 11 1.5.4 X âỵ dựng... M V C tro n g công nghệ J2EE S u n 73 11 1.3 .1 Giới thiệu công nghệ J E E 73 11 1.3.2 Thành p h ần V ie w 73 11 1.3.3 T hành p h ần M o d e l 74 11 1.3.4 Thành p