struts整合hibernate 报错:java.lang.NoClassDefFoundError: org/hibernate/service/ServiceRegistry
直接运行hibernate的插入可以成功,但在strtus2的action里就不行了publicclasscheckActionextendsActionSupport{...
直接运行hibernate的插入可以成功,但在strtus2的action里就不行了
public class checkAction extends ActionSupport {
private String bookchecked;
private String count;
public String execute() throws Exception {
ActionContext ctx = ActionContext.getContext();
Integer id = (Integer)ctx.getSession().get("id");
if(getBookchecked()!=null&&getCount()!=null){
Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();
Customer customer=(Customer)session.get(Customer.class, id);
Integer bookid = Integer.parseInt(getBookchecked());
Book book = (Book)session.get(Book.class, bookid);
CustomerBook customerbook = new CustomerBook();
customerbook.setBook(book);
customerbook.setCustomer(customer);
customerbook.setCount(Integer.parseInt(getCount()));
session.save(customerbook);
try {
tx.commit();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
session.close();
return SUCCESS;
}
else
return INPUT;
}
public String getBookchecked() {
return bookchecked;
}
public void setBookchecked(String bookchecked) {
this.bookchecked = bookchecked;
}
public String getCount() {
return count;
}
public void setCount(String count) {
this.count = count;
}
} 展开
public class checkAction extends ActionSupport {
private String bookchecked;
private String count;
public String execute() throws Exception {
ActionContext ctx = ActionContext.getContext();
Integer id = (Integer)ctx.getSession().get("id");
if(getBookchecked()!=null&&getCount()!=null){
Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();
Customer customer=(Customer)session.get(Customer.class, id);
Integer bookid = Integer.parseInt(getBookchecked());
Book book = (Book)session.get(Book.class, bookid);
CustomerBook customerbook = new CustomerBook();
customerbook.setBook(book);
customerbook.setCustomer(customer);
customerbook.setCount(Integer.parseInt(getCount()));
session.save(customerbook);
try {
tx.commit();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
session.close();
return SUCCESS;
}
else
return INPUT;
}
public String getBookchecked() {
return bookchecked;
}
public void setBookchecked(String bookchecked) {
this.bookchecked = bookchecked;
}
public String getCount() {
return count;
}
public void setCount(String count) {
this.count = count;
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询