Bom dia.
Estou enfrentando um problema em relação ao exercício 2 - Capitulo 6.4 - JavaServer Pages da apostila FJ21.
O exercicio solicita que eu formate uma ‘Data de Nascimento’ para que ela apareça no Scriplet como SimpleDateFormat("dd/MM/yyyy).
Na classe Data Acess Object no metodo getLista(), alterei de forma que a ‘Data de Nascimento’ seja capturada em uma String, fiz a conversão para SimpleDateFormat, instanciei uma variavel do tipo Calendar e passei como parametro a ‘Data de Nascimento’ já formatada no metodo setDataNascimento() do JavaBean.
Nas classes utilizadas e no JSP o Eclipse não acusa nenhum erro. Porém quando acesso o JSP no navegador, retorna a exception que declarei no web.xml.
Metodo dentro do Dao para capturar os dados do banco e retornar numa lista:
public List<Contato> getLista() throws ParseException {
try {
List<Contato> contatos = new ArrayList<Contato>();
PreparedStatement stmt = this.connection.prepareStatement(
"SELECT * FROM contatos");
ResultSet rs = stmt.executeQuery();
while(rs.next()) {
Contato contato = new Contato();
contato.setId(rs.getLong("id"));
contato.setNome(rs.getString("nome"));
contato.setEndereco(rs.getString("Endereco"));
contato.setEmail(rs.getString("email"));
String pegaData = rs.getString("dataNascimento");
Calendar dataNascimento = null;
java.util.Date data = new SimpleDateFormat("dd/MM/yyyy")
.parse(pegaData);
dataNascimento = Calendar.getInstance();
dataNascimento.setTime(data);
contato.setDataNascimento(dataNascimento);
contatos.add(contato);
}
rs.close();
stmt.close();
return contatos;
}
catch(SQLException e) {
throw new RuntimeException(e);
}
}
Scriplet JSP
<%@ page import=“java.util.,
br.com.caelum.jdbc.dao.,
br.com.caelum.jdbc.modelo.*” %>
<head>
<meta charset="UTF-8">
</head>
<body>
<table>
<%
ContatoDao dao = new ContatoDao();
List<Contato> contatos = dao.getLista();
for(Contato contato : contatos) {
%>
<tr>
<td><%=contato.getNome() %></td>
<td><%=contato.getEmail() %></td>
<td><%=contato.getEndereco() %></td>
<td><%=contato.getDataNascimento() %></td>
</tr>
<%
}
%>
</table>
</body>
Stacktrace do Tomcat
jan 13, 2017 3:47:26 AM org.apache.catalina.loader.WebappClassLoaderBase checkStateForResourceLoading
INFORMAÇÕES: Illegal access: this web application instance has been stopped already. Could not load [com.mysql.jdbc.SQLError]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load [com.mysql.jdbc.SQLError]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading(WebappClassLoaderBase.java:1295)
at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForClassLoading(WebappClassLoaderBase.java:1283)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1148)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1109)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3321)
at com.mysql.jdbc.MysqlIO.quit(MysqlIO.java:1667)
at com.mysql.jdbc.ConnectionImpl.realClose(ConnectionImpl.java:4322)
at com.mysql.jdbc.ConnectionImpl.cleanup(ConnectionImpl.java:1348)
at com.mysql.jdbc.ConnectionImpl.finalize(ConnectionImpl.java:2679)
at java.lang.System$2.invokeFinalize(System.java:1270)
at java.lang.ref.Finalizer.runFinalizer(Finalizer.java:98)
at java.lang.ref.Finalizer.access$100(Finalizer.java:34)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:210)
jan 13, 2017 3:47:26 AM org.apache.catalina.loader.WebappClassLoaderBase checkStateForResourceLoading
INFORMAÇÕES: Illegal access: this web application instance has been stopped already. Could not load [com.mysql.jdbc.ProfilerEventHandlerFactory]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load [com.mysql.jdbc.ProfilerEventHandlerFactory]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading(WebappClassLoaderBase.java:1295)
at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForClassLoading(WebappClassLoaderBase.java:1283)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1148)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1109)
at com.mysql.jdbc.ConnectionImpl.realClose(ConnectionImpl.java:4346)
at com.mysql.jdbc.ConnectionImpl.cleanup(ConnectionImpl.java:1348)
at com.mysql.jdbc.ConnectionImpl.finalize(ConnectionImpl.java:2679)
at java.lang.System$2.invokeFinalize(System.java:1270)
at java.lang.ref.Finalizer.runFinalizer(Finalizer.java:98)
at java.lang.ref.Finalizer.access$100(Finalizer.java:34)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:210)
jan 13, 2017 3:47:26 AM org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet [jsp] in context with path [/fj21-agenda] threw exception [javax.servlet.ServletException: java.text.ParseException: Unparseable date: “1995-01-24”] with root cause
java.text.ParseException: Unparseable date: "1995-01-24"
at java.text.DateFormat.parse(DateFormat.java:366)
at br.com.caelum.jdbc.dao.ContatoDao.getLista(ContatoDao.java:62)
at org.apache.jsp.lista_002dcontatos_002dscriplet_jsp._jspService(lista_002dcontatos_002dscriplet_jsp.java:126)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:745)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1437)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
S.O. Ubuntu 16.10
Eclipse Neon
JDK 8
Tomcat 9