Problem listing data in JSP

-1

I can not do the Data Listing. You are giving the "Error processing request", Servlet Path: /pages/dados.jsp Path Info: null Query String: null ... I do not know what it is. Grateful for any help. Note: I'm starting with the back end, my beach is front ...

MedicoDAO.java

public HashSet<Medico> listarMedicos() throws Exception {

    Connection conn = ClickConnection.getInstance().conectarBD();

    HashSet<Medico> listMedico = new HashSet<Medico>();

    try {

    // Criando a String SQL
    String sql = "select * from medico order by id_medico asc";

    // Criar o PreparedStatement, objeto para executar a query
    PreparedStatement preStatement = conn.prepareStatement(sql);

    ResultSet resultSet = preStatement.executeQuery();

        // Verifica se retornou dados na consulta
        while (resultSet.next()) {

                int codigo = resultSet.getInt(1);
                String CBO = resultSet.getString(2);    
                String CPF  = resultSet.getString(3);
                String UF = resultSet.getString(4);
                String cidade = resultSet.getString(5);
                String conselho = resultSet.getString(6);
                String email = resultSet.getString(7);
                String nome = resultSet.getString(8);
                String numeroConselho = resultSet.getString(9);
                String senha = resultSet.getString(10);
                String sexo = resultSet.getString(11);
                String sobre = resultSet.getString(12);
                String telCelular = resultSet.getString(13);
                String telResidencial = resultSet.getString(14);

                Medico medico = new Medico(codigo, nome, sexo, CPF, email, CBO, conselho, numeroConselho, senha, UF, cidade, telResidencial, telCelular, sobre);

                    listMedico.add(medico);
                    System.out.println("\nMédico no Banco de Dados:");
                    System.out.println(medico.toStringBasica());
                }
        return listMedico;

            } catch (Exception e) {
                System.out.println("Erro: "+e.getMessage());
            }

            System.out.println("\nNão Existe Médico no Banco de Dados!");
            return null;

}

ServletMedico.java

package com.leefgoedcode.clicksaude.servlets;

import java.io.IOException;
import java.io.PrintWriter;
import javax.annotation.Resource;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.NotSupportedException;
import javax.transaction.RollbackException;
import javax.transaction.SystemException;
import javax.transaction.UserTransaction;

import com.leefgoedcode.clicksaude.entidades.Medico;

@WebServlet("/ServletMedico")
public class ServletMedico extends HttpServlet {
    private static final long serialVersionUID = 1L;

    @PersistenceContext
    private EntityManager em;

    @Resource
    private UserTransaction ut;

    public ServletMedico() {
        super();
    }



    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {



        response.setContentType("text/html");
        response.setCharacterEncoding("utf-8");

        String nome = request.getParameter("nome");
        String sexo = request.getParameter("sexo");
        String CPF = request.getParameter("cpf");
        String email = request.getParameter("email");
        String CBO = request.getParameter("cbo");
        String conselho = request.getParameter("conselho");
        String numeroConselho = request.getParameter("numerodoconselho");
        String senha = request.getParameter("senha");
        String UF = request.getParameter("uf");
        String cidade = request.getParameter("cidade");
        String telResidencial = request.getParameter("telResidencial");
        String telCelular = request.getParameter("telCelular");
        String sobre = request.getParameter("sobre");

        Medico medico = new Medico();

        medico.setNome(nome);
        medico.setSexo(sexo);
        medico.setCPF(CPF);
        medico.setEmail(email);
        medico.setCBO(CBO);
        medico.setConselho(conselho);
        medico.setNumeroConselho(numeroConselho);
        medico.setSenha(senha);
        medico.setUF(UF);
        medico.setCidade(cidade);
        medico.setTelResidencial(telResidencial);
        medico.setTelCelular(telCelular);
        medico.setSobre(sobre);


        try {
            ut.begin();

            //Inserir DADOS no Banco
            em.persist(medico);

            ut.commit();
        } catch (SecurityException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NotSupportedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SystemException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (RollbackException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (HeuristicMixedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (HeuristicRollbackException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        PrintWriter out = response.getWriter();

        RequestDispatcher dispatcher = request.getRequestDispatcher("/pages/dados.jsp");
        request.setAttribute("lista", out);
        dispatcher.forward(request, response);




    }

data.jsp

<%@page import="java.util.ArrayList"%>

    

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <meta charset="utf-8">
    <link rel="shortcut icon" href="favicon.ico">

    <title>Médicos Cadastrados</title>

</head>

<body>


<nav class="navbar navbar-dark navbar-expand-lg">
<!-- Navbar content -->
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo01" aria-controls="navbarTogglerDemo01" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarTogglerDemo01">
        <a class="navbar-brand" href="../index.jsp"><img src="./imgs/logo2.png"></a>
            <ul class="navbar-nav mr-auto mt-2 mt-lg-0">
                <li class="nav-item active">
                    <a class="nav-link" href="./index.jsp">Página Inicial <span class="sr-only">(current)</span></a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Ajuda</a>
                </li>
            </ul>
    </div>
</nav>

<br>
    <div class="container-fluid">
        <div class="row">
        <div class="col-12">

        <div class="float-left cad-button">
            <a href="./pages/cadastros/cad_medico.jsp"><button id="btn-cadastrar-medico" type="button" class="btn btn-primary">Cadastrar Médico</button></a>
        </div>


            <div class="table-responsive">

                <table class="table table-bordered table-hover">
                    <thead class="thead-light">
                        <tr>
                            <th class="text-center" scope="col">ID</th>
                            <th scope="col">Nome Completo</th>
                            <th scope="col">E-mail</th>
                            <th scope="col">CBO</th>
                            <th scope="col">Conselho</th>
                            <th scope="col">Número do Celular</th>
                        </tr>
                    </thead>

                    <tbody>
                    <%
                    MedicoDAO dao = new MedicoDAO();
                    HashSet<Medico> listaMedicos = dao.listarMedicos();
                    for(Medico medico : listaMedicos){
                    %>
                        <tr>
                            <th class="text-center" scope="row">1</th>
                            <td></td>
                            <td class="text-center"><%=medico.getId_medico()%></td>
                            <td><%=medico.getNome()%></td>
                            <td><%=medico.getEmail()%></td>
                            <td><%=medico.getConselho()%></td>
                            <td><%=medico.getNumeroConselho()%></td>
                            <td><%=medico.getTelCelular()%></td>
                        </tr>
                    <%
                                                        }//for
                    %>              
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    </div>

</body>

</html>
    
asked by anonymous 19.05.2018 / 23:17

1 answer

0

I have already identified the error and corrected it. The error was in MedicoDAO and in the Medical entity.

    
21.05.2018 / 16:23