<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC '-//Sun Microsystems, Inc.//DTD Web
Application 2.2//EN' 'http://java.sun.com/j2ee/dtds/web-app_2.2.dtd'>
<web-app>
<servlet>
<servlet-name>Imetric</servlet-name>
<servlet-class>com.imetrics.Imetric</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>jdbcDriver</param-name>
<param-value>sun.jdbc.odbc.JdbcOdbcDriver</param-value>
</init-param>
<init-param>
<param-name>jdbcURL</param-name>
<param-value>jdbc:odbc:imetrics</param-value>
</init-param>
<init-param>
<param-name>jdbcUser</param-name>
<param-value>imetrics</param-value>
</init-param>
<init-param>
<param-name>jdbcPassword</param-name>
<param-value>imetrics</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Imetric</servlet-name>
<url-pattern>/Imetric/*</url-pattern>
</servlet-mapping>
<mime-mapping>
<extension>html</extension>
<mime-type>text/html</mime-type>
</mime-mapping>
<mime-mapping>
<extension>htm</extension>
<mime-type>text/html</mime-type>
</mime-mapping>
<mime-mapping>
<extension>pdf</extension>
<mime-type>application/pdf</mime-type>
</mime-mapping>
<mime-mapping>
<extension>gif</extension>
<mime-type>image/gif</mime-type>
</mime-mapping>
<mime-mapping>
<extension>jpg</extension>
<mime-type>image/jpeg</mime-type>
</mime-mapping>
<mime-mapping>
<extension>jpeg</extension>
<mime-type>image/jpeg</mime-type>
</mime-mapping>
</web-app>
My servlet, Imetric, is in the web-inf\classes\com\imetrics directory
structure.
I am just trying to get the servlet to load a connection pool, but it
won't even write to the log file in Tomcat. I don't believe Tomcat can
find the servlet.
Here is my servlet:
package com.imetrics;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.SQLException;
import java.sql.DriverManager;
import java.sql.Connection;
//import com.bitmechanic.sql.*;
/**
* @author Josh Kuebel(IVC, Inc.)
* @version 0.2.1
*/
public abstract class Imetric extends HttpServlet {
protected String jdbcDriver;
protected String jdbcURL;
protected String jdbcPassword;
protected String jdbcUser;
//private ConnectionPoolManager pool;
/**Initialize global variables*/
public void init(ServletConfig config) throws ServletException {
//super.init(config);
//ServletContext context = config.getServletContext();
log("I am here");
jdbcDriver = config.getInitParameter("jdbcDriver");
if (jdbcDriver == null) {
throw new ServletException("You must specify a jdbcDriver in the
ServletContext");
}
//context.log("jdbcDriver = " + jdbcDriver);
jdbcURL = config.getInitParameter("jdbcURL");
if (jdbcURL == null) {
throw new ServletException("You must specify a jdbcURL in the
ServletContext");
}
log("jdbcURL = " + jdbcURL);
jdbcUser = config.getInitParameter("jdbcUser");
if (jdbcUser == null) {
throw new ServletException("You must speficy a jdbcUser in the
ServletContext");
}
log("jdbcUser = " + jdbcUser);
jdbcPassword = config.getInitParameter("jdbcPassword");
if (jdbcPassword == null) {
throw new ServletException("You must specify the jdbcPassword in
the ServletContext");
}
log("jdbcPassword is set (but I'm not telling you to what).");
try {
//Make sure the driver is loaded
Class.forName(jdbcDriver);
} catch (Exception e) {
e.printStackTrace();
throw new ServletException("Caught exception when trying to to
create JDBC connection", e);
}
//Create the DataSource to use for the pool
//try
//{
//pool = new ConnectionPoolManager(120);
//pool.addAlias("imetrics", jdbcDriver, jdbcURL, jdbcUser,
jdbcPassword,10,0,0);
//}
//catch (Exception e) {
//e.printStackTrace();
//throw new ServletException("Caught exception when trying to to
create JDBC connection", e);
//}
}
}
It compiles without a problem. Any help would be appreciated.
Thanks,
Josh K
<snip>
One guess is that Tomcat might not be able to find the bitmechanic
classes - where have you put them?
--
Jon Skeet - <sk...@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Jon,
I have commented out any code related to the bitmechanic classes. When
I try to load the servlet from a browser, I get the following error:
java.lang.InstantiationException: com.imetrics.Imetric
at java.lang.Class.newInstance0(Native Method)
at java.lang.Class.newInstance(Class.java:237)
at org.apache.tomcat.core.ServletWrapper.loadServlet(ServletWrapper.java:268)
at org.apache.tomcat.core.ServletWrapper.init(ServletWrapper.java:289)
at org.apache.tomcat.core.Handler.service(Handler.java:254)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:210)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
at java.lang.Thread.run(Thread.java:484)
Josh
That suggests that something is going wrong when it's creating an
instance. At this stage you need to put lots of debugging in your
instance initialisers etc - or run it in a debugger.