I am having difficulty with getting this work. I can connect to the database without problem, however I can not make it show me the html page. It does not run.
I get the following error any body knows why?
The reason why you are getting that error body is that your handler for ClassNotFoundException
is throwing away the original exception stacktrace. You are writing the original exception's message to System.err
but (obviously) that won't go into the normal system logs. (You'll probably find find the message in the "catalina.out" file ... depending on how Tomcat is configured / launched.)
The right way to do this is to either chain the exception; e.g.
throw new ServletException("Class not found Error", e);
or log it explicitly at the point that you catch it. And if you do log it explicitly, make sure that you log the exception, and not just the exception message.
We can't tell you the actual root cause of the problem unless we see the original exception stacktrace ... but the two most likely causes are:
Tomcat expects that your servlet will be in a package. Yours appears to be in the default package; please add one and recompile. I'll bet things will go better for you then.
Tomcat 6 and 7 expect to find JDBC JARs in the server /lib directory. Add your PostgreSQL JDBC JAR to the server /lib location.
Seem you did't add Postgresql JDBC driver into classpath, as the following error suggest:
javax.servlet.ServletException: Class not found Error
Which is origin from:
throw new ServletException("Class not found Error");
You can download Postgresql JDBC driver and put in PROJECT/WEB-INF/lib
folder.
Suggestion
One suggestion, your exception handling is wrong, you should change
throw new ServletException("Class not found Error");
to
throw new ServletException("Class not found Error", e);