Pessoal, boa noite.
Como faço para que meu Servidor Tomcat reconheca meu driver JDBC? Devo colar o jar em alguma pasta do tomcat, criar alguma pasta (como LIB no meu projeto)?
Segue o código, lembrando que não terminei ainda!
Pagina JSP:
<%--
Document : index
Created on : 06/02/2011, 13:16:44
Author : THIAGO
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Agenda de Contatos</title>
</head>
<body>
<h1 align ="center">Agenda de Contatos - Principal</h1><hr/>
<table>
<form action="adicionaContato" method="get">
<tr>
<td>Nome:<p><input type ="text" name ="nome" size="45"></p></td>
<td>Email:<p><input type="text" name="email" size="45"> <input type="submit" name="adicionar" value="Adicionar"></p></td>
</tr>
</form>
<tr>
<td>Nome:<p><input type ="text" name ="nome" size="45"> <input type="submit" name="excluir" value="Excluir"></p></td>
</tr>
</table>
</body>
</html>
Servlet:
[code]
package Servlet;
import java.io.IOException;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javaBeans.Contato;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class AdicionaContatoServlet extends HttpServlet{
@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
//acesso ao bean
Contato c = new Contato();
c.setNome(request.getParameter("nome"));
c.setEmail(request.getParameter("email"));
try
{
//adiciona ao BD
new DAO.AdicionaContato().adiciona(c);
System.out.println("Contato adicionado com sucesso...");
}
catch (SQLException ex)
{
System.out.println("Falha na inclusão do Contato!");
}
}
}
WEB.XML
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>AdicionaContato</servlet-name>
<servlet-class>Servlet.AdicionaContatoServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AdicionaContato</servlet-name>
<url-pattern>/adicionaContato</url-pattern>
</servlet-mapping>
</web-app>
Segue o codigo de erro do NetBeans:
org.apache.catalina.loader.StandardClassLoader@1172e08
servlet.AdicionaContatoServlet
java.lang.ClassNotFoundException: servlet.AdicionaContatoServlet
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1095)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:809)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
06/02/2011 19:50:02 org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Allocate exception for servlet AdicionaContato
java.lang.ClassNotFoundException: servlet.AdicionaContatoServlet
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1095)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:809)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
06/02/2011 20:30:36 org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextDestroyed()
06/02/2011 20:30:36 org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextDestroyed()
06/02/2011 20:31:41 org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
06/02/2011 20:31:41 org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
Grato desde já pela ajuda!
=D