Good evening. Guys, I have a question which after N attempts does not clear up, so I decided to ask the masters for help. Basically, I have the following servlet:
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("Chamando doGet");
PrintWriter resposta = resp.getWriter();
resposta.println("<html><body>");
resposta.println("<strong>TESTANDO FORTE</strong>");
resposta.println("<ul>");
for (Artista u : new ArtistaDAO().getArtistas()) {
resposta.println("<li>" + u.getNome() + "</li>");
}
resposta.println("</ul>");
resposta.println("</body></html>");
RequestDispatcher disp = req.getRequestDispatcher("/WEB-INF/views/inicio.jsp");
disp.forward(req, resp);
}
This servlet, (which has urlPatterns="/ get_artist") When accessed by / get_artist returns me a simple html list of registered artists. However, I would like to get this list on my JSP page (Dashboard) as soon as the user logs in. I know it's possible to use with taglib:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
...
...
...
<c:forEach var="item" items="${artistas}">
<ul>
<li>Nome: ${item.getNome}</li>
</ul>
</c:forEach>
However, for this taglib to work, should I have another servlet that returns another list?
I'm trying to get through with the following servlet (but it's not working):
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
synchronized(this){
ArrayList<Artista> artistas = new ArtistaDAO().getArtistas();
req.setAttribute("artistas", artistas);
RequestDispatcher disp = req.getRequestDispatcher("/WEB-INF/views/inicio.jsp");
}
}
In short, my question is: How do I get all my ArrayList artists and display them on the dashboard as soon as a user logs in?