Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_jsp thread: Servlet hangs and will not forward


Message #1 by "Greg Dunn" <greg.dunn@n...> on Thu, 14 Mar 2002 16:56:28 -0600
This servlet is supposed to check whether a table name exists on a d/b
server and either respond with HTML informing the user if so or forward to
another servlet if not.

It seems to be failing or hanging somewhere.  The browser shows a blank page
and stops there, no exceptions or other info is coming from the server.  I'm
running it on Tomcat 3.3.  I know the servlet is getting invoked because if
I introduce an exception Tomcat shows it, and if I put a few out.println in
they will show up to the point of the exception.  If anyone sees anything
wrong here I would appreciate the assistance.  Thanks.

---------code------------------------------------


import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import cc.nisc.surveymanager.beans.DBConnectionManager;
import cc.nisc.surveymanager.beans.LogWriter;

public class ValidateResponseTable extends HttpServlet {

    private DBConnectionManager connMgr = DBConnectionManager.getInstance();
    Connection con = connMgr.getConnection("SurveyManager");
    ResultSet rs = null;
    Statement stmt = null;
    private LogWriter errorLog = LogWriter.getInstance();

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

    public void doPost(HttpServletRequest request, HttpServletResponse
response)
     throws ServletException, IOException {
	    response.setContentType("text/html");
	    PrintWriter out = response.getWriter();

	    String query = "";
        String surveyTable = request.getParameter("surveyTable");

        query = "SELECT name FROM sysobjects " +
                "WHERE name = '" + surveyTable + "' AND type = 'U'";

        try {
            stmt = con.createStatement();
            rs = stmt.executeQuery(query);

            if (rs.next()) {
                out.println("<html>");
                out.println("<head><title>Validate Response
Table</title></head>");
                out.println("<body>");
                out.println("<p>A table named</p>");
                out.println("<h3>" + surveyTable + "</h3>");
                out.println("<p>Already exists</p>");
                out.println("<p><b>Please Select a different name</b></p>");
                out.println("<a href=\"javascript:history.back()\">Go
back</a>");
                out.println("</body></html>");

                rs.close();
                stmt.close();
                connMgr.freeConnection("SurveyManager", con);
                connMgr.release();
            }
            else {

                rs.close();
                stmt.close();
                connMgr.freeConnection("SurveyManager", con);
                connMgr.release();

                RequestDispatcher rd 

getServletContext().getRequestDispatcher("/surveymanager/" +

"servlet/cc.nisc.surveymanager.servlets.GenerateSurvey");
                rd.forward(request, response);
            }
        }
        catch(SQLException e) {
            e.printStackTrace();
        }
    }
}


  Return to Index