Can I use Javabeans with hibernate?
I'm using a hibernate2 plugin in my web project with jsp. My project also contains a register page.
Can I use Javabeans to send information from a html <form>
using hibernate's class? Without hibernate I created a class with get and set like this:
package com.java2s;
public class Lang {
private String choix;
private String comm;
public String getChoix() {
return choix;
}
public void setChoix(String choix) {
this.choix = choix;
//System.out.println(choix);
}
public String getComm() {
return comm;
}
public void setComm(String comm) {
this.comm = comm;
// System.out.println(comm);
}
}
but I know that hibernate generates a 开发者_如何学运维get and set class and receives it with:
<jsp:useBean id='user' class='com.java2s.Lang' type='com.java2s.Lang' scope='session' />
<jsp:setProperty name='user' property='*'/>
any idea how to do that?
Hibernate 2? The current version is 3.6.5; I'd upgrade. Your JSP should not have any Hibernate code in it; it should submit the form to a servlet, which will validate and bind the request parameters to objects and then persist using Hibernate.
i get what i need i call MyDB.Etudinat
from the pakage genrated by hibernate
on a beans in my jsp page
and i save it like that
<%
if(user.getUserName()!=null){
Session hibernateSession = MyDB.HibernateUtil.currentSession();
Transaction tx = hibernateSession.beginTransaction();
Etudinat etudiant = new Etudinat();
etudiant.setUserName(user.getUserName());
etudiant.setPassword(user.getPassword());
etudiant.setEmail(user.getEmail());
etudiant.setNom(user.getNom());
etudiant.setPrenom(user.getPrenom());
etudiant.setSexe(user.getSexe());
etudiant.setQuestion(user.getQuestion());
etudiant.setAnswer(user.getAnswer());
etudiant.setIDFilliere(Filliere.INFORMATIQUE);
/* out.print("<Li>"+user.getUserName());
out.print("<Li>"+user.getPassword());
out.print("<Li>"+user.getEmail());
out.print("<Li>"+user.getNom());
out.print("<Li>"+user.getPrenom());
out.print("<Li>"+user.getSexe());
out.print("<Li>"+user.getQuestion());
out.print("<Li>"+user.getAnswer());
*/
hibernateSession.save(etudiant);
tx.commit();
HibernateUtil.closeSession();
}
%>
i wish that will help outhers
精彩评论