Session session;
Transaction tx;
public void add(Admin admin) throws HibernateException {
/**
* Creation Date: 11-17-2005
* TODO Add a new admin user.
* @param An object of Admin
* @return void
* @author Coder Guo
*/
try {
session = SessionFactory.currentSession();
tx = session.beginTransaction();
//Add a new admin
session.save(admin);
tx.commit ();
}catch(HibernateException e){
throw e;
}finally{
if (tx!=null) {
tx.rollback();
}
SessionFactory.closeSession();
}
}
// --------------------------------------------------------- Instance Variables
// --------------------------------------------------------- Methods
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @author Coder Guo
*/
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
AddAdminForm addAdminForm = (AddAdminForm) form;
// TODO Add a new admin
Admin admin = new Admin();
admin.setName(addAdminForm.getName ());
admin.setPassword(addAdminForm.getPassword ());
AdminDAOFactory adminDAO = new AdminDAOFactory ();
adminDAO.add(admin);
return mapping.findForward("success");
}
public ActionErrors validate(
ActionMapping mapping,
HttpServletRequest request) {
// TODO Auto-generated method stub
ActionErrors errors = new ActionErrors();
Session session = SessionFactory.currentSession();
Transaction tx = session.beginTransaction ();
Query query = session.createQuery("select admin from Admin as admin where admin.name = '" + this.name + "'");
Iterator it = query.iterate ();
if (it.hasNext()){
errors.add ("addAdmin.err.name",new ActionMessage("form.addAdmin.err.name"));
}
tx.commit();
SessionFactory.closeSession ();
return errors;
}
public void reset(ActionMapping mapping, HttpServletRequest request) {
// TODO Auto-generated method stub
this.name=null;
this.password=null;
}
if (loginForm.userName.value == "" || loginForm.password.value == ""){
alert("
loginForm.userName.focus();
return false;
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<head>
<html:base />
<title>login.jsp</title>
<link href="css/webcss.css" rel="stylesheet" type="text/css">
<meta http-equiv="pragma" content="no- cache">
<meta http-equiv="cache-control" content="no- cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http- equiv="description" content="This is my page">
</head>
<body>
<center>
<p> </p>
<p> </p>
<table width="300" border="0" cellpadding="0" cellspacing="0">
<html:form action="/addAdmin" focus="name" method="GET">
<tr align="center" valign="middle">
<td colspan="2" class="typt_normal">
</tr>
<tr>
<td width="100" align="center" valign="middle" class="typt_normal">
<td width="200" align="left"><html:text property="name" styleClass="text_s"/><html:errors property="addAdmin.err.name"/></td>
</tr>
<tr>
<td width="100" align="center" valign="middle" class="typt_normal">
<td width="200" align="left"><html:password property="password" styleClass="text_s"/></td>
</tr>
<tr>
<td colspan="2" align="center" valign="middle"><html:submit value="
</tr>
</html:form>
</table>
</center>
</body>