[RESOLVIDO] HTTP Status 500 – An exception occurred processing

Queria uma ajuda, a horas estou tentando ver uma solução e não conseguir.

 <html>
    <body>
        <table>
            <%
                ContactDao dao = new ContactDao();
                List<Contact> contacts = dao.getContacts();

                for (Contact contact : contacts) {
            %>
                    <tr>
                        <td><%=contact.getName() %></td>
                        <td><%=contact.getEmail() %></td>
                        <td><%=contact.getAddress() %></td>
                        <td><%=contact.getBirthDate().getTime() %></td>
                    </tr>
            <%
                }
            %>
        </table>
    </body>
</html>

Classe ContactDao

public class ContactDao {
    private Connection connection;

    public ContactDao() {
        this.connection = new ConnectionFactory().getConnection();
    }

    public List<Contact> getContacts() {
        try {
            List<Contact> contactList = new ArrayList<>();

            PreparedStatement statement = connection.prepareStatement("SELECT * FROM contacts");

            ResultSet resultSet = statement.executeQuery();

            while (resultSet.next()) {
                Contact contact = new Contact();

                contact.setName(resultSet.getString("firstName"));
                contact.setEmail(resultSet.getString("email"));
                contact.setAddress(resultSet.getString("address"));

                Calendar date = Calendar.getInstance();
                date.setTime(resultSet.getDate("birthDate"));
                contact.setBirthDate(date);

                contactList.add(contact);
            }

            resultSet.close();
            statement.close();

            return contactList;
        } catch (SQLException e) {
            throw new DaoException();
        }
    }

    public void add(Contact contact) {
        try {
            PreparedStatement add = connection.prepareStatement(
                    "INSERT INTO contacts (firstName, email, address, birthDate) VALUES (?, ?, ?, ?)");

            add.setString(1, contact.getName());
            add.setString(2, contact.getEmail());
            add.setString(3, contact.getAddress());
            add.setDate(4, new Date(contact.getBirthDate().getTimeInMillis()));

            add.executeUpdate();
            add.close();
        } catch (SQLException e) {
            throw new DaoException();
        }
    }

    public void update(Contact contact) {
        try {
            PreparedStatement update = connection.prepareStatement(
                    "UPDATE contacts SET firstName = ?, email = ?, address = ?, birthDate = ? WHERE id = ?");

            update.setString(1, contact.getName());
            update.setString(2, contact.getEmail());
            update.setString(3, contact.getAddress());
            update.setDate(4, new Date(contact.getBirthDate().getTimeInMillis()));
            update.setLong(5, contact.getId());

            update.executeUpdate();
            update.close();
        } catch (SQLException e) {
            throw new DaoException(e.getMessage());
        }
    }

    public void delete(Contact contact) {
        try {
            PreparedStatement delete = connection.prepareStatement("DELETE FROM contacts WHERE id = ?");

            delete.setLong(1, contact.getId());

            delete.executeUpdate();
            delete.close();
        } catch (SQLException e) {
            throw new DaoException();
        }
    }
}

Root

java.lang.RuntimeException
	jdbc.ConnectionFactory.getConnection(ConnectionFactory.java:12)
	jdbc.dao.ContactDao.<init>(ContactDao.java:16)
	org.apache.jsp.list_002dcontacts_002dscriptle_jsp._jspService(list_002dcontacts_002dscriptle_jsp.java:124)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:444)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

    org.apache.jasper.JasperException: An exception occurred processing [/list-contacts-scriptle.jsp] at line [9]

    6:     <body>
7:         <table>
8:             <%
9:                 ContactDao dao = new ContactDao();
10:                 List<Contact> contacts = dao.getContacts();
11: 
12:                 for (Contact contact : contacts) {

Stacktrace:

    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:593)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:482)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

Olá, seu erro está nesta classe e linha. Provavelmente problemas de conexão a banco, reveja isso.

Segue abaixo os testes na conexão do banco, e um teste em listar contatos, o erro acontece no banco apenas no código do jsp.

Banco de dados

public class ConnectionFactory {
    public Connection getConnection() {
        try {
            return DriverManager.getConnection("jdbc:mysql://localhost/fj21", "root", "root");
        } catch (SQLException e) {
            throw new RuntimeException();
        }
    }
}

Teste de conexão

public class TestConnection {
    public static void main(String[] args) throws SQLException {
        Connection connection = new ConnectionFactory().getConnection();
        System.out.println("Open connection!");
        connection.close();
    }
}

Resultado do Teste

Open connection!

Process finished with exit code 0

Teste listar contatos

public class TestContactList {
    public static void main(String[] args) throws SQLException{
        ContactDao dao = new ContactDao();

        List<Contact> contacts = dao.getContacts();

        for (Contact contact : contacts) {
            System.out.printf("%s%n%n", contact);
        }
    }
}

Resultado do teste

Nome: Danilo Almeida
Email: danilo.eru@gmail.com
Address: Rua João Francisco Alves, 15 - Mangabeira
Birth Date: 19/11/1990

Nome: Diogo Almeida
Email: diogomc3@gmail.com
Address: Rua João Francisco Alves, 15
Birth Date: 06/02/2000

Nome: Aldi Alves
Email: aldijp@gmail.com
Address: Rua João Francisco Alves, 15 - Mangabeira
Birth Date: 20/07/1980

Nome: Ana Lucia
Email: analucia@gmail.com
Address: Rua João Francisco Alves, 15 - Mangabeira
Birth Date: 21/09/1970


Process finished with exit code 0

Tente importar as classes na página JSP.

<%@ page import="fully.qualified.name.sua.Classe, fully.qualified.name.outra.Classe" %>

@raphaeloneves já estava com as classes importadas, tentei isolar o erro para facilitar, e vou dar uma pesquisada para ver, isolei o erro apenas tentando acessar o banco de dados pelo JSP. Tem alguma biblioteca que teria que está importada, ou configuração no Tomcat? Lembrando o problema que estou tendo com JSP é apenas quando tento acessar o banco de dados.

<%@ page import="java.sql.Connection" %>
<%@ page import="jdbc.ConnectionFactory" %>
<%@ page import="java.sql.SQLException" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
    <head>
        <title>Test Connection</title>
    </head>
    <body>
        <%
            try {
                Connection connection = new ConnectionFactory().getConnection();
                out.println("Open connection");
                connection.close();
            } catch (SQLException e) {
                throw new RuntimeException();
            }
        %>
    </body>
</html>

Exception

org.apache.jasper.JasperException: An exception occurred processing [/test-connection.jsp] at line [12]

9:     <body>
10:         <%
11:             try {
12:                 Connection connection = new ConnectionFactory().getConnection();
13:                 out.println("Open connection");
14:                 connection.close();
15:             } catch (SQLException e) {

Stacktrace

	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:593)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:482)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

Root

java.lang.RuntimeException
	jdbc.ConnectionFactory.getConnection(ConnectionFactory.java:12)
	org.apache.jsp.test_002dconnection_jsp._jspService(test_002dconnection_jsp.java:127)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:444)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

Resolvi o problema incluindo a linha:

<% Class.forName("com.mysql.jdbc.Driver"); %>

Adicionando o driver do MySQL na pasta do projeto, abaixo o caminho:

out/artifacts/NomeProjeto_war_exploded/WEB-INF/lib/mysql-connector-java-5.1.42-bin

Eu já tinha ele na biblioteca, mas tive que coloca-la na pasta de saída também.
Obrigado a todos que ajudaram.

Fonte:

https://stackoverflow.com/questions/25074949/java-lang-classnotfoundexception-com-mysql-jdbc-driver-on-eclipse