- 论坛徽章:
- 0
|
发错了应该是:
eclipse+strust+hibernate,做一个小demo主要的功能是讲表单中的数据持久化的数据库中,在单独调用hibernate的情况下是可以写入数据库的,然后,写一个test代码如下
package com.hibmapping;
import org.hibernate.*;
import org.hibernate.cfg.*;
public class Test {
public void insert(String Username,String Userpwd) {
try {
SessionFactory sf = new Configuration().configure().buildSessionFactory();
Session session = sf.openSession();
Transaction tx = session.beginTransaction();
Userlist user = new Userlist();
user.setUsername(Username);
user.setUserpwd(Userpwd);
session.save(user);
tx.commit();
session.close();
} catch (HibernateException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
Test test=new Test();
test.insert("w","wf");
}
}
后在Action中execute调用insert报错,
exception
javax.servlet.ServletException: Servlet execution threw an exception
root cause
java.lang.NoClassDefFoundError: org/hibernate/HibernateException
com.struts.action.HihibAction.execute(HihibAction.java:46)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
Action中的execute函数
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response){
HihibForm hihibForm = (HihibForm) form;
System.out.println("call execute");
Test test=new Test();
test.insert("wufei","success!@");
return mapping.findForward("hihib_forward");
} |
|