分类: Java
2007-01-04 11:09:43
图4 系统体系结构图 |
public class OrAdmin implements Serializable{ private String adminname; public String getAdminname() { return adminname; } Public void setAdminname(String adminname) { this.adminname = adminname; } …… } |
public abstract class DAOFactory { public static DAOFactory getInstance() {} public abstract AdminDAO createAdminDAO(); } public class AdminDAOImpl implements AdminDAO { public OrAdmin getAdmin(String adminName) { try { Session s =HibernateUtil.currentSession(); Query query = s.createQuery("from OrAdmin as oa whereoa.adminname='"+adminName+"'"); }…… return null; } } |
<session-factory > <property name="connection.driver_class"> org.postgresql.Driver </property> <property name="connection.url"> jdbc:postgresql://127.0.0.1:5432/DBInfo </property> <property name="dialect"> org.hibernate.dialect.PostgreSQLDialect </property> <mapping resource="OrAdmin.hbm.xml" /> …… </session-factory> |
public class ManagerFactory { public static AdminManager createAdminManager(){ return new AdminManagerImpl(); } } public interface AdminManager { OrAdmin getAdmin(String username); } public class AdminManagerImpl implements AdminManager{ private AdminDAO dao =DAOFactory.getInstance().createAdminDAO(); public OrAdmin getAdmin(String username) { return this.dao.getAdmin(username); } } |
public class AdminActionForm extends ActionForm { private String adminname; public String getAdminname() { eturn adminname;} public void setAdminname(String adminname) { his.adminname = adminname; } …… } |
public class AdminAction extends Action { AdminActionForm adminActionForm =(AdminActionForm) actionForm; adminname=adminActionForm.getAdminname(); adminpasswd=adminActionForm.getAdminpd(); AdminManager adminManager=ManagerFactory.createAdminManager(); OrAdmin orAdmin=adminManager.getAdmin(adminname); if(orAdmin == null||!orAdmin.getAdminpasswd().equals(adminpasswd)){ servletRequest.getSession().setAttribute("loginfail","Invalid name or password. Login failture"); return actionMapping.findForward("logout"); }else{ servletRequest.getSession().setAttribute("adminname",adminname); return actionMapping.findForward("success"); } } |
<form-beans> <form-bean name="adminActionForm" type="com.rice.web.struts.from.AdminActionForm" /> </form-beans> <action-mappings> <action name="adminActionForm" path="/adminAction" scope="session" type="com. rice.web.struts.action.AdminAction"validate="false"> <forward name="success" path="/manager/main.jsp" /> <forward name="logout" path="/manager/index.jsp" /> </action> </action-mappings> |