Answer the question
In order to leave comments, you need to log in
Can't see the config file?
Hello.
I'm trying to write a web project using a tutorial, adding users and displaying them (two pages in the end). I wanted to add Hibernate to the project so that the data is then stored in the database. When adding a user (namely, when creating a session), an error occurs.
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String name = req.getParameter("name");
String password = req.getParameter("pass");
User user = new User(name, password);
Model model = Model.getInstance();
model.add(user);
SessionFactory sessionFactory = new Configuration()
.configure()
.buildSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
session.save(user);
session.getTransaction().commit();
sessionFactory.close();
req.setAttribute("userName", name);
doGet(req, resp);
}
Answer the question
In order to leave comments, you need to log in
sviato_slav @sviato_slav
Timofey Lanevich, I mean the availability of the library during program execution.
1) you have an incorrect project structure. The web folder should be named webapp and located in src/main.
2) Add the line to the pom file:
war
After downloading your project and fixing it, I was able to run it without any problems without errors.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question