gpt4 book ai didi

eclipse - hibernate 和 Eclipse 错误

转载 作者:行者123 更新时间:2023-11-28 23:54:57 24 4
gpt4 key购买 nike

我正在创建一个带有注册表单的简单 Web 应用程序,并且我使用了 Hibernate。但是我有这种错误:

这是代码:AddUser.java

import java.io.IOException;

import javax.imageio.spi.ServiceRegistry;
import javax.security.auth.login.Configuration;
import javax.servlet.RequestDispatcher;
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 org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;


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


public AddUser() {
super();
// TODO Auto-generated constructor stub
}


protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Configuration config = new Configuration().configure("hibernate.cfg.xml");
ServiceRegistry servReg = new StandardServiceRegistryBuilder().applySettings(config.getProperties()).build();
SessionFactory factory = config.buildSessionFactory(servReg);

Session session = factory.openSession();
session.beginTransaction();
User u = new User(request.getParameter("firstname"), request.getParameter("lastname"), request.getParameter("login"), request.getParameter("password"));
session.save(u);
session.getTransaction().commit();
session.close();

RequestDispatcher view = request.getRequestDispatcher("useradd.jsp");
view.forward(request, response);

}

}

这是错误:ERROR我该怎么做才能解决这个问题?谢谢!

@LuisMuñoz

如果有人想直接看到它,我也会添加错误。

HTTP Status 500 – Internal Server Error

Type Exception Report

Message Servlet execution threw an exception

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

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

java.lang.Error: Unresolved compilation problems:
Cannot instantiate the type Configuration
The method configure() is undefined for the type Configuration
The method getProperties() is undefined for the type Configuration
The method buildSessionFactory(ServiceRegistry) is undefined for the type Configuration

AddUser.doPost(AddUser.java:32)
javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Note The full stack trace of the root cause is available in the server logs.

我的 Eclipse 页面: ECLIPSE

最佳答案

从错误来看,配置对象似乎没有配置方法。检查 javadocs https://docs.oracle.com/javase/9/docs/api/index.html?javax/security/auth/login/Configuration.html

关于eclipse - hibernate 和 Eclipse 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51087284/

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