MVC模式在Java Web应用程序中的实例分析
结合六个基本质量属性
可用性:
异常
可修改性:
1.维持语义的一致性,高内聚低耦合
2.维持现有的接口,Login依赖LoginIService接口,LoginService依赖ILogDAO
性能:暂无
安全性:
对用户进行身份验证
易用性:暂无
分析具体功能模块的MVC设计实现(例如登录、用户权限等功能模块)
在实际项目中的具体应用或分析MVC设计模式在具体网站中的应用(需要列举实例)
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");//防止弹出的信息出现乱码 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 |
//输入用户名,密码,验证码,返回(id,msg)是否错误和错误信息 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]="未知错误"; try { if(!srand.equals(randcode)) { msg[0]="Error"; msg[1]="验证码错误"; return msg; } } catch (Exception e) {
msg[0]="Error"; msg[1]="验证码错误"; return msg; }
try{ Log result=logdao.findById(user); if(result==null) { msg[0]="Error"; msg[1]="账号不存在"; return msg; } if(!result.getPassword().equals(pwd)) { msg[0]="Error"; msg[1]="密码错误"; return msg; } bm=result.getBm();
} catch (Exception e) { msg[0]="Error"; msg[1]="账号密码错误"; 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); }
} |