You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jason Tesser <JT...@nbbc.edu> on 2004/02/17 19:53:02 UTC

servlet help please

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


Re: servlet help please

Posted by jugal <jr...@colorfly.com>.
hi
tell me one thing...that u added the servlet tag in ur web.xml file or 
not...
if not then add it to web.xml file
<servlet>
<servlet-name>MessageServlet1</servlet-name>
<servlet-class>MessageServlet1</servlet-class>
</servlet>

try with this.......
 programme runs???...or not run????....let me know

by by
jugal

Jason Tesser wrote:

>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
>
>  
>




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