gpt4 book ai didi

java.lang.ClassNotFoundException : javax. 持久性.PersistenceException

转载 作者:行者123 更新时间:2023-12-02 10:54:39 25 4
gpt4 key购买 nike

我是 Hibernate、servlet 的新手。我正在尝试使用 hibernate 从 html 注册表将数据存储在 mysql 数据库中。但是我不断收到此错误作为根本原因。这是弹出的两个根本原因。

HTTP status 500 Internal server error.

Exception

javax.servlet.ServletException: Servlet execution threw an exception
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Root Cause

java.lang.NoClassDefFoundError: javax/persistence/PersistenceException
java.base/java.lang.ClassLoader.defineClass1(Native Method)
java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1007)
java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2339)
org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:829)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1278)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1137)
kish.hibernate.servletController.registerData.doGet(registerData.java:30)
javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Root Cause

java.lang.ClassNotFoundException: javax.persistence.PersistenceException
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1309)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1137)
java.base/java.lang.ClassLoader.defineClass1(Native Method)
java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1007)
java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2339)
org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:829)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1278)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1137)
kish.hibernate.servletController.registerData.doGet(registerData.java:30)
javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

这是我的 hibernate.cfg.xml 文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configurationn>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>
<property name="hibernate.connection.password">Kish</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/demo</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="hbm2ddl.auto">create</property> <!-- create table every time -->
<property name="show_sql">true</property>
<mapping class="kish.hibernate.Pojo.Student"></mapping>

</session-factory>

</hibernate-configurationn>

这是我的 html 文件

<html> 
<head>
<title> RegistrationForm</title>
<link rel = "stylesheet" type = "text/css" href = "style1.css">
<body>


<div class= "registrationBox">
<img src= "avatar1.png" class= "avatar">
<h1> enter your details below form</h1>

<form action = "registerData" method ="get">
<p>Firstname</p>
<input type="text" name="first_name" placeholder="Enter your firstname">
<p>Lastname</p>
<input type = "text" name= "last_name" placeholder="Your lastname ">
<p>Branch</p>
<input type = "text" name="branch" placeholder="your branch">
<p>Id</p>
<input type = "text" name = "Id" placeholder="your id">
<p>password</p>
<input type="password" name="password" placeholder="create your password">
<input type="submit" name="submit" value = "confirm">
</form>
</div>

</body>
</head>
</html>

servlet 文件registerData.java

[package kish.hibernate.servletController;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import kish.hibernate.DAO.MainController;

@WebServlet("/registerData")
public class registerData extends HttpServlet {
private static final long serialVersionUID = 1L;

public registerData() {
super();
}


protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String first_name = request.getParameter("first_name");
String last_name = request.getParameter("last_name");
String branch = request.getParameter("branch");
int Id = Integer.parseInt(request.getParameter("Id"));
String password = request.getParameter("password");


MainController mc = new MainController();
mc.addUserDeatails(first_name, last_name, branch, Id, password);
response.sendRedirect("success");

}

}

如果需要,我将发布任何进一步的数据。

任何建议表示赞赏。 谢谢。

编辑:

“javax.persistence.jar”

它显然包含“javax.persistence.PersistenceException.class”

添加了这个 jar,但仍然显示相同的错误。

updated jar file in classpath

最佳答案

将您的 jar 放在 WEB-INF/lib 文件夹下。构建您的项目。它会起作用的。

关于java.lang.ClassNotFoundException : javax. 持久性.PersistenceException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51864229/

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