2
Good morning guys, I’m implementing the get a Servlet method here with a very simple logic.
If the user passes a url in the default: ".../entities/id", the editing form should be opened with the entity corresponding to the id entered after the bar. But if the url pattern is: ".../entities" the list of all entities will be loaded and the entity listing page opened.
Everything is already working, but with a problem. After running the last line it is facing the start of the get method, as if something is calling the get method, then it is in infinite loop.
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String requestUri = req.getRequestURI();
Long id = RegexUtil.matchId(requestUri);
if (id != null) {
// Informou um id
Entidade entidade = entidadeService.getEntidadeById(id);
if (entidade != null) {
req.setAttribute("objEntidade", entidade);
req.getRequestDispatcher("paginas/cadastroentidades.jsp").forward(req, resp);
// Após executar esta linha, volta automaticamente para a primeira linha do método
} else {
resp.sendError(404, "Entidade não encontrada");
}
} else {
List<Entidade> lstEntidades = entidadeService.getEntidades();
req.setAttribute("lstEntidades", lstEntidades);
req.getRequestDispatcher("paginas/listaentidades.jsp").forward(req, resp);
// Após executar esta linha, volta automaticamente para a primeira linha do método
}
}
Any help is welcome.
Hello Leonardo Villela, thanks for the tip, I will test tonight and put here if it is solved.
– Silvair L. Soares
Hello anything, if it helps do not forget to mark the question as answered and evaluate the answer, good studies :)
– Leonardo Villela
Thanks, Leonardo Villela, I decided here following your tip.
– Silvair L. Soares