Question : Tomcat 4.0.6 The requested resource is not available

Hello,
I'm trying to learn to use Tomcat/Java. My experience is with Apache/PHP and ZOPE/Python. I'm using Tomcat and MySQL on Win98, but I'm also uploading and testing on servers running on Suse Linux. I've been downloading various JSP/Servlet code samples that select from a MySQL dbase and output results in HTML. The following servlet was adapted from the "MySQL Bedrock database" sample that can be found on the Inet. It compiles, deploys and executes OK, but the web page just displays:

"Apache Tomcat/4.0.6 - HTTP Status 404 - /servlet/ShowEmployee
The requested resource (/servlet/ShowEmployee) is not available."


------------------------
/* A servlet to display the contents of the MySQL Inout database */

import java.io.*;
import java.net.*;
import java.sql.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ShowEmployee extends HttpServlet
{
    public String getServletInfo()
    {
       return "Servlet connects to MySQL database and displays result of a SELECT";
    }

    // Use http GET

    public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String loginUser = "un";
        String loginPasswd = "pwd";
        String loginUrl = "jdbc:mysql://localhost/inout";

        response.setContentType("text/html");    // Response mime type

        // Output stream to STDOUT
        PrintWriter out = response.getWriter();

        out.println("<TITLE>EmployeeE>");
        out.println("

Employee

");

        // Load the mm.MySQL driver
        try
           {
              Class.forName("org.gjt.mm.mysql.Driver");
              Connection dbcon = DriverManager.getConnection(loginUrl, loginUser, loginPasswd);
              // Declare our statement
              Statement statement = dbcon.createStatement();

              String query = "SELECT FNAME, LNAME, ";
              query +=       " AVAILABILITY ";
              query +=       "FROM employee ";

              // Perform the query
              ResultSet rs = statement.executeQuery(query);

              out.println("");

              // Iterate through each row of rs
              while (rs.next())
              {
                  String m_fname = rs.getString("FNAME");
                  String m_lname = rs.getString("LNAME");
                  String m_avail = rs.getString("AVAILABILITY");
                  out.println("" +
                              "" +
                              "" +
                              "" +
                              "");
              }

              out.println("
" + m_fname + "" + m_lname + "" + m_avail + "
");

              rs.close();
              statement.close();
              dbcon.close();
            }
        catch (SQLException ex) {
              while (ex != null) {
                    System.out.println ("SQL Exception:  " + ex.getMessage ());
                    ex = ex.getNextException ();
                }  // end while
            }  // end catch SQLException

        catch(java.lang.Exception ex)
            {
                out.println("" +
                            "" +<br />                            "Employee: Error" +<br />                            "\n" +
                            "

SQL error in doGet: " +
                            ex.getMessage() + "

");
                return;
            }
         out.close();
    }
}
--------------------------

I've tried deplying the servlet through the NetBeans IDE, as well as launching Tomcat through DOS and installing the servlet with Tomcat manager URI's, but either way, the servlet remains unavailable. I've seen various posting that say to do different things with the mappings in the "web.xml" etc, but I still don't understand how I can resolve my issue.

Why won't Tomcat serve up my servlet?


Answer : Tomcat 4.0.6 The requested resource is not available

add "package ShowEmployee;" to the top of your java compile and try.
Random Solutions  
 
programming4us programming4us