Pessoal,
estou tentando criar um servlet que no método init() leia alguns parâmetros de configuração definidos para esse servlet. Ocorre que sempre que executo um request ao servlet o mesmo não consegue ler os parâmetros definidos no web.xml apresentando a mensagem de erro abaxo:
[code]type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: you must specify the ‘database’, ‘user’, ‘passwd’ init params to -> com.ack.servlets.JDBCTest[/code]
Alguma ajuda?
Jakarta Tomcat 4.1.26
Java 1.4.2_08
Segue a classe e o web.xml
[code]package com.ack.servlets;
import java.io.;
import javax.servlet.;
import javax.servlet.http.;
import java.sql.;
public class JDBCTest extends HttpServlet {
private static final long serialVersionUID = 6186313746193288185L;
private Connection fConnection;
public void init(ServletConfig config) throws ServletException
{
super.init(config);
String jdbcURL = config.getInitParameter("database");
String username = config.getInitParameter("user");
String password = config.getInitParameter("passwd");
UnavailableException uex = null;
if( jdbcURL == null )
{
System.out.println("JDBC is NULL");
}
if( username == null )
{
System.out.println("USERNAME is NULL");
}
if( password == null )
{
System.out.println("PASSWORD is NULL");
}
if( jdbcURL == null || username == null || password == null )
{
StringBuffer buf = new StringBuffer("you must specify the ");
buf.append (" 'database', 'user', 'passwd' init params to -> ");
buf.append( getClass().getName() );
String msg = buf.toString();
log( msg );
throw new ServletException( msg );
}
try
{
// register drivers...
fConnection = DriverManager.getConnection(jdbcURL,username,password);
// do some work here...
}
catch( SQLException sqle )
{
log( sqle.toString() );
uex = new UnavailableException ( sqle.toString(), 15 );
}
finally
{
// release connection in the event of problems
if( uex != null )
try { fConnection.close(); } catch(SQLException e) {}
}
log( "Completed Servlet Initialisation for: " + getClass().getName() );
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
System.out.println("Log-passei aqui");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Hello World</title></head>");
out.println("<body> Hey there people!");
out.println("</body></html>");
out.close();
}
}[/code]
[code]
<?xml version="1.0" encoding="ISO-8859-1"?> test com.ack.servlets.JDBCTest database DBase user usuario passwd Senha [/code]