help me run my first servlet program

I am trying to learn j2ee, servlets and Ejb. i am having a nightmare in running my first servlet program. Here is how my TestingServler looks like. here is the directory where i stored my .java file

C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\myApp\WEB-INF\classes

import javax.servlet.*;

import javax.servlet.http.*;

import java.io.*;

import java.util.*;

publicclass TestingServletextends HttpServlet{

publicvoid doGet(HttpServletRequest request,

HttpServletResponse response)

throws ServletException, IOException{

PrintWriter out = response.getWriter();

out.println("<HTML>");

out.println("<HEAD>");

out.println("<TITLE>Servlet Testing</TITLE>");

out.println("</HEAD>");

out.println("<BODY>");

out.println("Welcome to the Servlet Testing Center");

out.println("</BODY>");

out.println("</HTML>");

}

}

The .class file is also over here

C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\myApp\WEB-INF\classes

and my web.xml file looks like this

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app

PUBLIC"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

<servlet>

<servlet-name>Testing</servlet-name>

<servlet-class>TestingServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>TestingServlet</servlet-name>

<url-pattern>/Testing</url-pattern>

</servlet-mapping>

</web-app>

and here is my web.xml file

C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\myApp\WEB-INF

and now this is what i am typing

http://localhost:8080/myApp/Testing

Not working. i am using tomcat 5.0. Please respond.

[2767 byte] By [lrngjavaa] at [2007-11-27 5:32:19]
# 1

1) You haven't put the servlet in a package.

2) You are using different servlet names in the <servlet> and the <servlet-mapping> declarations.

3) Start reading the [url=http://java.sun.com/javaee/5/docs/tutorial/doc/]Java EE tutorial[/url], servlets starts at chapter 3.

BalusCa at 2007-7-12 14:58:19 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

> 1) You haven't put the servlet in a package.

What Servlet package?

> 2) You are using different servlet names in the

> <servlet> and the <servlet-mapping> declarations.

I dont see any different name i am using Testing as a name and TestingServlet

> 3) Start reading the

> [url=http://java.sun.com/javaee/5/docs/tutorial/doc/]J

> ava EE tutorial[/url], servlets starts at chapter 3.

Yea thanks i will give a shot but that chapter does not tell you how to compile a servlet. by doing some research i came to know a little bit about invokerservlet. i had to make some changes in conf/web.xml file in tomcat. But still unsuccessful.

http://localhost:8080/myApp/servlet/Testing not working

http://localhost:8080/myApp/servlet/TestingServlet

is also not working

Message was edited by:

lrngjava

lrngjavaa at 2007-7-12 14:58:20 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

I am not sure if a Servlet must put inside a package, but if it does, if just like other simple java program.

e.g. package foo.bar;

<web-app>

<servlet>

<servlet-name>Testing</servlet-name> // name

<servlet-class>TestingServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>TestingServlet</servlet-name> // name (match?)

<url-pattern>/Testing</url-pattern>

</servlet-mapping>

</web-app>

rym82a at 2007-7-12 14:58:20 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
> What Servlet package?Your choice. 'com.irngjava.TestingServlet' or so?> I dont see any different name i am using Testing as a> name and TestingServletYou don't see a difference between 'Testing' and 'TestingServlet'? OK, then I'm lost.
BalusCa at 2007-7-12 14:58:20 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Try to change the configuration in web.xml to

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app

PUBLIC "-//Sun Microsystems, Inc.//DTD Web

Application 2.3//EN"

"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

<servlet>

<servlet-name>Testing</servlet-name>

<servlet-class>TestingServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>Testing</servlet-name>

<url-pattern>/Testing</url-pattern>

</servlet-mapping>

</web-app>

The value of the <servlet-name> tag has to be the same in the <servlet> tag as in the <servlet-mapping> tag. At least that is one mistake, I hope it is the only one.

toon_macharisa at 2007-7-12 14:58:20 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
You can take a look here; I'd had a little bit of trouble with servlets too so I've put up a little tutorial :) http://nogoodatcoding.googlepages.com/deployingaservletontomcat
nogoodatcodinga at 2007-7-12 14:58:20 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...