gpt4 book ai didi

java - HTTP 状态 500 - javax.servlet.ServletException : java. lang.NoClassDefFoundError: org/hibernate/Session

转载 作者:行者123 更新时间:2023-11-30 10:50:22 25 4
gpt4 key购买 nike

在这里,我在 Eclipse Mars 中使用 JSP 和 Hibernate 创建了一个简单的注册表单。当我运行一个 jsp 页面时,出现异常:

HTTP Status 500 - javax.servlet.ServletException: java.lang.NoClassDefFoundError: org/hibernate/Session.

我在这里放置了所需的文件和目录结构。

1)用户.java

package com.nick.mypack;
public class User {

private int id;
private String name,password,email;

public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}

}

2)UserDao.java

package com.nick.mypack;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class UserDao {

public static int register(User u){
int i=0;
Session session=new Configuration().
configure().buildSessionFactory().openSession();

Transaction t=session.beginTransaction();
t.begin();

i=(Integer)session.save(u);

t.commit();
session.close();

return i;
}
}

3)index.jsp

<html>
<form action="register.jsp" method="post">
Name:<input type="text" name="name"/><br><br/>
Password:<input type="password" name="password"/><br><br/>
Email ID:<input type="text" name="email"/><br><br/>
<input type="submit" value="register"/>"

</form>
</html>

4)注册.jsp

<%@page import="com.nick.mypack.UserDao" %>
<jsp:useBean id="obj" class="com.nick.mypack.User">
</jsp:useBean>
<jsp:setProperty property="*" name="obj"/>

<%
int i=UserDao.register(obj);
if(i>0)
out.print("You are successfully registered");
%>

This is a directory structure of a Project.

请帮我解决这个问题。提前致谢!

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com