I got basic "hello world" working:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class hello extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<html>");
out.println("<head><title>Hello World</title></head>");
out.println("<body>");
out.println("<center><h1>Hello World</h1></center>");
out.println("</body></html>");
}
}
but this simple variant fails (the non-servlet version that follows it
works fine); stacktrace follows it all --- CastException seems to be the
key point, but I don't see how casting would be any different between hello
and jth:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class jth extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
String db = "jdbc:mysql://localhost/alan";
res.setContentType("text/html");
PrintWriter out = res.getWriter();
try {
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
}
catch (Exception E) {
System.err.println("Unable to load driver.");
E.printStackTrace();
return;
}
try {
Connection con = DriverManager.getConnection(db, "alan", "xxx");
Statement select = con.createStatement();
ResultSet result = select.executeQuery("select * from test");
out.println("<html>");
out.println("<head>");
out.println("<title>Apache/Mysql/Tomcat/JDBC Test</title>");
out.println("</head>");
out.println("<body>");
out.println("<center>");
out.println("<h1>Apache/Mysql/Tomcat/JDBC Test</h1>");
out.println("<p>Results:");
out.println("<table border=1>");
out.println("<tr>");
out.println("<th>Name<th>Value");
while (result.next()) {
String n = result.getString(1);
String v = result.getString(2);
out.println("<tr><td>" + n + "<td>" + v);
}
out.println("</table>");
out.println("</center>");
out.println("</body>");
out.println("</html>");
select.close();
con.close();
}
catch (Exception E) {
E.printStackTrace();
return;
}
}
}
non-servlet version:
import java.sql.*;
public class jt {
public static void main(String args[]) {
String db = "jdbc:mysql://localhost/alan";
try {
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
}
catch (Exception E) {
System.err.println("Unable to load driver.");
E.printStackTrace();
return;
}
try {
Connection con = DriverManager.getConnection(db, "alan", "no2dos");
Statement select = con.createStatement();
ResultSet result = select.executeQuery("select * from test");
System.out.println("<html>");
System.out.println("<head>");
System.out.println("<title>Apache/Mysql/Tomcat/JDBC Test</title>");
System.out.println("</head>");
System.out.println("<body>");
System.out.println("<center>");
System.out.println("<h1>Apache/Mysql/Tomcat/JDBC Test</h1>");
System.out.println("<p>Results:");
System.out.println("<table border=1>");
System.out.println("<tr>");
System.out.println("<th>Name<th>Value");
while (result.next()) {
String n = result.getString(1);
String v = result.getString(2);
System.out.println("<tr><td>" + n + "<td>" + v);
}
System.out.println("</table>");
System.out.println("</center>");
System.out.println("</body>");
System.out.println("</html>");
select.close();
con.close();
}
catch (Exception E) {
E.printStackTrace();
return;
}
}
}
Error: 500
Location: /servlet/jth
Internal Servlet Error:
java.lang.ClassCastException: jth
at org.apache.tomcat.core.ServletWrapper.loadServlet(ServletWrapper.java)
at org.apache.tomcat.core.ServletWrapper.init(ServletWrapper.java)
at org.apache.tomcat.core.Handler.service(Handler.java)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java)
at
org.apache.tomcat.service.connector.Ajp13ConnectionHandler.processConnection(Ajp13ConnectionHandler.java)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java)
at java.lang.Thread.run(Thread.java)
--
Alan Batie ______ www.rdrop.com/users/alan Me
[EMAIL PROTECTED] \ / www.qrd.org The Triangle
PGPFP DE 3C 29 17 C0 49 7A \ / www.pgpi.com The Weird Numbers
27 40 A5 3C 37 4A DA 52 B9 \/ www.anti-spam.net NO SPAM!