T
T
Timofey Lanevich2018-10-12 16:06:02
Java
Timofey Lanevich, 2018-10-12 16:06:02

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);
    }

5bc09ae6c9f96263209047.png
Project on
github I can write projects individually, but if together, it does not see the configuration file for some reason.
Please help, I will be happy to help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Timofey Lanevich, 2018-10-12
@Timak31

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 question

Ask a Question

731 491 924 answers to any question