I'm new to MVC and I'm following this tutorial. I'm having a hard time showing the records by default when the page loads. This is what I see with my current code

Both methods from my sevlet work, the insertUser and the listAllUsers methods, but listAllUsers is not being executed by default when the page loads.
How can I show the content automatically when the website first loads ?
This is my servlet
@WebServlet("/") public class SvPeople extends HttpServlet { private UserDAO userDAO; public void init() { String jdbcURL = "jdbc:mysql://localhost:3306/dbpeople"; String jdbcUsername = "root"; String jdbcPassword = "1234"; userDAO = new UserDAO(jdbcURL, jdbcUsername, jdbcPassword); } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String action = request.getServletPath(); try { switch (action) { case "/insert": insertUser(request, response); break; default: listAllUsers(request, response); break; } } catch (SQLException ex) { throw new ServletException(ex); } } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } protected void listAllUsers(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException { List listUser = userDAO.listUsers(); request.setAttribute("listUser", listUser); RequestDispatcher dispatcher = request.getRequestDispatcher("list-users.jsp"); dispatcher.forward(request, response); } private void insertUser(HttpServletRequest request, HttpServletResponse response) throws SQLException, IOException { String name = request.getParameter("name"); User newUser = new User(name); userDAO.insertUser(newUser); response.sendRedirect("list-users.jsp"); } } and this is the JSP I'm using
Users My form!
SvPeople com.mycompany.crudtest.servlets.SvPeople SvPeople /SvPeople 30 list-users.jsp Thanks in advance.
Источник: https://stackoverflow.com/questions/780 ... eing-shown
Мобильная версия