点击这里给我发消息 点击这里给我发消息

MyEclipse+struts+Hibernate配置开发手册

添加时间:2013-12-7
    相关阅读: 开发 HTML


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>&nbsp;</p>

<p>&nbsp;</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>

咨询热线:020-85648757 85648755 85648616 0755-27912581 客服:020-85648756 0755-27912581 业务传真:020-32579052
广州市网景网络科技有限公司 Copyright◎2003-2008 Veelink.com. All Rights Reserved.
广州商务地址:广东省广州市黄埔大道中203号(海景园区)海景花园C栋501室
= 深圳商务地址:深圳市宝源路华丰宝源大厦606
研发中心:广东广州市天河软件园海景园区 粤ICP备05103322号 工商注册