Содержимое веб-сайта Java по умолчанию не отображаетсяJAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Содержимое веб-сайта Java по умолчанию не отображается

Сообщение Anonymous »


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!
Name: and lastly, I don't know if the issue comes from not having index.jsp as main page because I'm using a list-user.jsp as welcome file. Here is my web.xml

SvPeople com.mycompany.crudtest.servlets.SvPeople SvPeople /SvPeople 30 list-users.jsp Thanks in advance.


Источник: https://stackoverflow.com/questions/780 ... eing-shown
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»