Error running Servlet Nullpointerexception

Asked

Viewed 5 times

0

Hello, create a Servlet to be able to make changes to users registered in the bd. In this excerpt I try to recover the employee data by id and redirect to the change page:

    @Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try{
        int id = Integer.parseInt(request.getParameter("id"));
        ClienteDAO dao = new ClienteDAO();
        Cliente cliente = dao.getClientePorCodigo(id);
        if(cliente.getId() > 0 ){
            RequestDispatcher disp = getServletContext().getRequestDispatcher("/funcionario/Paginas/cadastrar.jsp");
            request.setAttribute("clientes", cliente);
            disp.forward(request, response);

        }
        else{
            PrintWriter out = response.getWriter();
            out.println("<script>alert('Usuário não encontrado!'); location.href = 'funcionario/Paginas/dashboard.jsp'</script>");
        }   
    }
    catch( IOException | NumberFormatException | ServletException e ){
        System.out.println("Erro ao recuperar dados");
        System.out.println("Erro: " + e.getMessage());
    }
}

but when I run the page is empty: inserir a descrição da imagem aqui

Would anyone know where this mistake of mine?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.