Combined with six basic mass properties
Availability of:
Abnormal
Modifiable:
1. maintain semantic consistency, cohesion low coupling
2. maintain the existing interface,Login relies on the loginiservice interface,loginservice dependent Ilogdao
Performance: No
Security:
Authenticating a user
Ease of use: not currently
analysis of specific function modules MVC Design implementations (such as login, user permissions, and other functional modules)
specific application or analysis in a real-world project Application of MVC design patterns to specific websites (examples are required)
Login |
Public String Execute () throws Exception { String[] Request=loginservice.userpan (user, pwd, randcode); Req.getsession (). SetAttribute ("username", user); HttpServletResponse response = Servletactioncontext. GetResponse (); Response.setcontenttype ("Text/html;charset=utf-8"); Response.setcharacterencoding ("UTF-8");//Prevent garbled information from popping up PrintWriter out = Response.getwriter (); if (Request[0].equals ("Error")) { Out.print ("<script>alert ('" +request[1]+ "');</script>"); Out.flush (); Out.close (); return "Error"; } return "Success"; } |
Loginiserivece |
Public String[] Userpan (String user,string pwd,string randcode); |
Loginservice |
Enter user name, password, verification code, return (ID,MSG) error and error message Public String[] Userpan (String user,string pwd,string randcode) { string[] msg = new string[2]; String bm= ""; HttpServletRequest Req=servletactioncontext. getrequest (); String srand= (String) req.getsession (). getattribute ("Rand");//session.setattribute ("Rand", Srand); Msg[0]= "Error"; msg[1]= "Unknown error"; Try { if (!srand.equals (Randcode)) { Msg[0]= "Error"; msg[1]= "Verification Code Error"; return msg; } } Catch (Exception e) { Msg[0]= "Error"; msg[1]= "Verification Code Error"; return msg; } Try { Log Result=logdao.findbyid (user); if (result==null) { Msg[0]= "Error"; msg[1]= "account does not exist"; return msg; } if (!result.getpassword (). Equals (PWD)) { Msg[0]= "Error"; msg[1]= "Password Error"; return msg; } BM=RESULT.GETBM (); } Catch (Exception e) { Msg[0]= "Error"; msg[1]= "Account password Error"; return msg; } Req.getsession (). SetAttribute ("BM", BM); Msg[0]= "Success"; return msg; } |
Ilogindao |
Public Log FindByID (java.lang.String ID); |
Logindao |
Public Log FindByID (java.lang.String ID) { log. Debug ("Getting Log instance with ID:" + ID); Try { Log instance = (log) gethibernatetemplate (). Get ("Interdao.dao.Log", ID); return instance; } catch (RuntimeException re) { log. Error ("Get Failed", re); throw re; } } |
Log |
Public class log Extends abstractlog implements java.io.serializable { //constructors /** default constructor */ public log () { } /** Minimal constructor */ Public log (string Username, string password, string role) { super (username, password, role); } /** Full constructor */ public log (string username, string Password, string role, String bm) { Super (username, password, role, BM); } } |
Instance analysis of the MVC pattern in a Java Web application