salut
les fichiers jar que j'utilise sont:
antlr-2.7.6rc1.jar hibernate3.jar log4j-1.2.11.jar asm-attrs.jar ehcache-1.1.jar cglib-2.1.3.jar dom4j-1.6.1.jar asm.jar db2j.jar
sacher que j'utilise hibernate Synchronizer 3.1.9 avec hibernate 3.2.je travaille comme outil RAD v6.0 [evaluation] dont websphere est intégré.
le code de ma servlet est:
package sample.actions;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; //import org.apache.struts.action.ActionError; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.hibernate.HibernateException; import org.hibernate.Session;
import sample.beans.Contact; import sample.actions.HibernateUtil; import sample.forms.ContactForm;
/** * @version 1.0 * @author */ public class AddContactAction extends Action
{
public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request, HttpServletResponse response) throws HibernateException, Exception {
ActionErrors errors = new ActionErrors(); ActionForward forward = new ActionForward();
Session session=null;
try { // Get instance of contactForm for reading values submitted through form ContactForm c = (ContactForm) form;
session = HibernateUtil.currentSession();
//Person aPerson = (Person) session.load(Person.class, personId);
session.beginTransaction(); //Create new instance of Contact and set values in it by reading them from form object Contact contact = new Contact(); contact.setId(Long.parseLong((String) c.getId())); contact.setFirstName((String) c.getFirstname()); contact.setLastName((String) c.getLastname()); contact.setEmail((String) c.getEmail()); session.save(contact);
session.getTransaction().commit();
request.setAttribute("displayContact", contact);
} catch (HibernateException e) { //If some thing goes wrong show failure page to user e.printStackTrace(); session.getTransaction().rollback(); forward = mapping.findForward("failure");
} finally { // Actual contact insertion will happen at this step HibernateUtil.closeSession();
} forward = mapping.findForward("sucess");
// If everything goes as per plan show contact details to user. return (forward); }
}
merci.
|