简体   繁体   English

我可以在休眠状态下使用Javabeans吗?

[英]Can I use Javabeans with hibernate?

I'm using a hibernate2 plugin in my web project with jsp. 我在jsp的网络项目中使用了hibernate2插件。 My project also contains a register page. 我的项目还包含一个注册页面。

Can I use Javabeans to send information from a html <form> using hibernate's class? 我可以使用Hibernate的类使用Javabeans从html <form>发送信息吗? Without hibernate I created a class with get and set like this: 没有休眠,我创建了一个带有get和set的类,如下所示:

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: 但我知道休眠会生成一个get和set类并通过以下方式接收它:

<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? 休眠2? The current version is 3.6.5; 当前版本是3.6.5。 I'd upgrade. 我会升级。 Your JSP should not have any Hibernate code in it; 您的JSP中不应包含任何Hibernate代码。 it should submit the form to a servlet, which will validate and bind the request parameters to objects and then persist using Hibernate. 它应该将表单提交给Servlet,该Servlet将验证请求参数并将其绑定到对象,然后使用Hibernate持久化。

i get what i need i call MyDB.Etudinat from the pakage genrated by hibernate on a beans in my jsp page 我得到我需要的MyDB.Etudinat从jsp页面中的bean上由休眠生成的包中调用MyDB.Etudinat

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 我希望这将有助于

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM