Hi,

My environment is - Windows98, JDK1.2.2, JSDK 2.0, Apache+Jserv

I was trying to send some data from doGet() generated html to some database through 
JDBC-ODBC connection. But when I press SUBMIT, I got the following error:
                                               THE  DOCUMENT CONTAINED NO DATA

My code is attached herewith.

Thanks.

Sabbir



_______________________________________
Rewards for everyday Internet use
/****************************************************************
/ This program is to perform the student registration on-line.
/ Using JDBC-SERVLET
/
/ Registration.java
/
/ Date 03/01/2000
/
/ Author : Kazi Sabbir Ahmed
/
/*****************************************************************/

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;


public class Registration extends HttpServlet
{
        protected Connection dbCon;
        protected String dbURL  = "jdbc:odbc:StudentData";
        protected PreparedStatement registerStatement;

        // Data field position

        protected final int NAME_POSITION     = 1;
        protected final int USERID_POSITION   = 2;
        protected final int PASSWORD_POSITION = 3;
        protected final int METRICNO_POSITION = 4;
        protected final int CLASSID_POSITION  = 5;
        protected final int EMAIL_POSITION    = 6;


        //protected String userID = "sabbir";
        //protected String passwd = "sabbir";

        public void init(ServletConfig config) throws ServletException {
                super.init(config);

                // use println statements to send status message
                // to server console

                try {
                        System.out.println ("Registration init : Start");
                        System.out.println ("Registration init : Loading Drivers..");
                        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

                        System.out.println ("Registration init : Getting a Getting a 
connection to - " + dbURL);
      dbCon = DriverManager.getConnection(dbURL, "sabbir", "sabbir");

      System.out.println("Registration init : Preparing register statement");
      registerStatement = dbCon.prepareStatement("INSERT INTO profile" +
        "(Name, UserID, Password, MetricNo, ClassID, Email)" +
                " values (?,?,?,?,?,?)");

      System.out.println("StudentDBServlet init: End");
    }
    catch (Exception e)
    {
      cleanUp();
      e.printStackTrace();
    }
  }

        public void doGet(HttpServletRequest req,
                HttpServletResponse res) throws ServletException, IOException{

                        // Set MIME type for HTTP Header

                        res.setContentType("text/html");

                        // Get a handle to the output stream

                        PrintWriter out = res.getWriter();

                        out.println("<HTML><HEAD>");
                        out.println("<TITLE>Student Registration Page</TITLE>");
                        out.println("</HEAD>");
                        out.println("<H2>Welcome to Student Registration Page 
for</H2><BR>");
                        out.println("<H1>ITS for Digital Systems</H1><HR>");
                        out.println("<FORM METHOD =\"POST\" ACTION="
                                +"\"http://sabbir.ite.edu.sg/servlets/Registration\" 
>");
                        out.println("<P> Name      : <INPUT TYPE=\"TEXT\" 
NAME=\"name\" "+
                                "SIZE=\"30\"<BR>");
                        out.println(" User ID   : <INPUT TYPE=\"TEXT\" NAME=\"userID\" 
"+
                                "SIZE=\"8\"<BR>");
                        out.println(" Password  : <INPUT TYPE=\"PASSWORD\" 
NAME=\"passwd\" "+
                                "SIZE=\"8\"<BR>");
                        out.println(" Metric No : <INPUT TYPE=\"TEXT\" NAME=\"metric\" 
"+
                                "SIZE=\"11\"<BR>");
                        out.println(" Email     : <INPUT TYPE=\"TEXT\" NAME=\"email\" 
"+
                                "SIZE=\"30\"<BR>");
                        out.println(" Class ID  : <INPUT TYPE=\"TEXT\" 
NAME=\"classID\" "+
                                "SIZE=\"8\"</P>");
                        out.println("<INPUT TYPE=\"SUBMIT\" VALUE=\"Submit\" >"+
                                "<INPUT TYPE=\"RESET\" VALUE=\"Reset\" >");
                        out.println("</FORM></BODY></HTML>");

                        out.close();
                } // End of doGet

                public void doPost(HttpServletRequest req, HttpServletResponse res)
                        throws IOException {

                                // Set MIME type for HTTP header
                                res.setContentType("text/html");

                                // get data from request object

                                String name     = req.getParameter("name");
                                String userID   = req.getParameter("userID");
                                String passwd   = req.getParameter("passwd");
                                String metric   = req.getParameter("metric");
                                String email    = req.getParameter("email");
                                String classID  = req.getParameter("classID");

                                try {
                                        registerStatement.setString(NAME_POSITION, 
name);
                                        registerStatement.setString(USERID_POSITION, 
userID);
                                        registerStatement.setString(PASSWORD_POSITION, 
passwd);
                                        registerStatement.setString(METRICNO_POSITION, 
metric);
                                        registerStatement.setString(CLASSID_POSITION, 
classID);
                                        registerStatement.setString(EMAIL_POSITION, 
email);
                                } catch (SQLException e) {
                                        e.printStackTrace();
                                }
                }       // End of doPost

                public void cleanUp(){
                        try {
                                System.out.println("Closing database connection");
                                dbCon.close();
                        } catch (SQLException e) {
                                e.printStackTrace();
                        }
                } // End of cleanup

                public void destroy() {
                        System.out.println("Registration : destroy");
                        cleanUp();
                } // End of destroy

                public String getServletInfo() {
                        return "Name  : Registration.java \r\n"+
       "Author: Kazi Sabbir Ahmed \r\n"+
       "Created with Kawa 3.2, JDK 1.2 and JSDK 2.0";
                }

}// End of Registration

Reply via email to