0
Good evening. People, I have a question that after N attempts is not clarified, 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 the urlPatterns = "/artist search") When accessed by /artist search returns me a simple list in html of the registered artists. However, I would like to get this list on my JSP (Dashboard) page as soon as the user logs in. I know it is 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 I must 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");
}
}
To sum up my question: How to get all my Arraylist artists and show on Dashboard as soon as a user logs in?