I try to follow a servlet example [Chapter_5/SQLSampleServlet.java] in the book "mastering tomcat development" by Peter Harrison/Ian McFarland, but run into a problem.
Your help is greatly appreciated. Many Thanks.
yi-ren
My setup:
-----------------------------------------------------------
Apache Tomcat/4.1.18 and httpd/2.0.47 using connector mod_jk-2.0.43.so
[java version "1.4.2"]
javac -classpath common/lib/servlet.jar webapps/examples/WEB-INF/classes/SQLSampleServlet.java
-----------------------------------------------------------
Here is the error messages:
----------------------------------------------------
javax.servlet.UnavailableException
at SQLSampleServlet.init(SQLSampleServlet.java:22)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:934)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:666)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:432)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:386)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:534)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:530)
at java.lang.Thread.run(Thread.java:534)
----------------------------------------------------
Here is the part of the code that causes the problem:
----------------------------------------------------
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class SQLSampleServlet extends HttpServlet{
private Connection con;
public void init(ServletConfig config) throws ServletException
{
String driver = config.getInitParameter("database-driver-class"
String jdbcurl = config.getInitParameter("database-url"
String login = config.getInitParameter("database-login"
String password = config.getInitParameter("database-password"
try
{
//error comes from here
Class.forName(driver); // Load the driver
con = DriverManager.getConnection(jdbcurl, login, password);
}
catch (Exception e)
{
throw new UnavailableException(e.getMessage());
}
}
public void doGet(HttpServletRequest request, HttpServletResponse response) {
//This part works OK.
}
}
Your help is greatly appreciated. Many Thanks.
yi-ren
My setup:
-----------------------------------------------------------
Apache Tomcat/4.1.18 and httpd/2.0.47 using connector mod_jk-2.0.43.so
[java version "1.4.2"]
javac -classpath common/lib/servlet.jar webapps/examples/WEB-INF/classes/SQLSampleServlet.java
-----------------------------------------------------------
Here is the error messages:
----------------------------------------------------
javax.servlet.UnavailableException
at SQLSampleServlet.init(SQLSampleServlet.java:22)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:934)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:666)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:432)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:386)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:534)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:530)
at java.lang.Thread.run(Thread.java:534)
----------------------------------------------------
Here is the part of the code that causes the problem:
----------------------------------------------------
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class SQLSampleServlet extends HttpServlet{
private Connection con;
public void init(ServletConfig config) throws ServletException
{
String driver = config.getInitParameter("database-driver-class"
String jdbcurl = config.getInitParameter("database-url"
String login = config.getInitParameter("database-login"
String password = config.getInitParameter("database-password"
try
{
//error comes from here
Class.forName(driver); // Load the driver
con = DriverManager.getConnection(jdbcurl, login, password);
}
catch (Exception e)
{
throw new UnavailableException(e.getMessage());
}
}
public void doGet(HttpServletRequest request, HttpServletResponse response) {
//This part works OK.
}
}