tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jason Tesser" <JTes...@nbbc.edu>
Subject servlet help please
Date Tue, 17 Feb 2004 18:53:02 GMT
OK I am new to Tomcat and I am going through one of Sun's courses
regarding Web apps.  I am working on the below example; I have complied
the code ok 
And put it in the servlets-examples/classes.  I also went into the
web.xml File under the servlets-examples directory and added the
following
	<servlet-mapping>
		<servlet-name>MessageServlet1</servlet-name>
		<url-pattern>/servlet/MessageServlet1</url-pattern>
	</servlet-mapping>

The problem is when I add the above code to the xml file nothing Under
servlets-examples will run.  What am I doing wrong?

Here is the java code for MessageServlet1 

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
// Support classes
import java.io.IOException;
import java.io.PrintWriter;


public class MessageServlet1 extends HttpServlet {

  private static final String[] MESSAGES = {
    "How are you today?",
    "What's in a name? That which we call a rose by any other name would
smell as sweet.",
    "My hovercraft is full of eels."
  };

  public void doGet(HttpServletRequest request,
		    HttpServletResponse response)
	 throws IOException {

    // Pick a random message
    int msg_index = (int) (Math.random() * MESSAGES.length);
    String message = MESSAGES[msg_index];

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();

    out.println("<HTML>");
    out.println("<HEAD>");
    out.println("<TITLE>Message Servlet</TITLE>");
    out.println("</HEAD>");
    out.println("<BODY BGCOLOR='white'>");
    out.println("The message is: <BR>");
    out.println("<BLOCKQUOTE>" + message + "</BLOCKQUOTE>");
    out.println("</BODY>");
    out.println("</HTML>");

    out.close();
  }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message