Problem viewing a hello world servlet

I am doing the Introduction to Java Servelet Technology tutorial from the ibm website.

I created a hello world servlet:

import java.io.IOException;

import java.io.PrintWriter;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

public class HelloWorldServlet extends HttpServlet { // HelloWorldServlet is underlined in red, when I mouse over // the error message is: does not declare a final static UID for type long

public void service(HttpServletRequest request,

HttpServletResponse response)

throws ServletException, IOException {

PrintWriter writer = response.getWriter();

writer.println("Hello, World!");

writer.close();

}

}

I started my tom cat.

I created my XML file that I need to put in my WEB-INF folder:C:\Eclipse\HelloWorld\WEB-INF

--

<!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>hello</servlet-name>

<servlet-class>HelloWorldServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>hello</servlet-name>

<url-pattern>/hello</url-pattern>

</servlet-mapping>

</web-app>

-

When I browse to: http://localhost:8080/HelloWorld/hello

I get this:

HTTP Status 404 - /HelloWorld/hello

-

Not sure if this has anything to do with it:

In my eclipse when is tarted tom cat (I have the plug in ).

This is what I got in the out file:

Aug 24, 2006 4:56:28 PM org.apache.struts.util.PropertyMessageResources <init>

INFO: Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true

Aug 24, 2006 4:56:28 PM org.apache.struts.util.PropertyMessageResources <init>

INFO: Initializing, config='org.apache.struts.util.LocalStrings', returnNull=true

Aug 24, 2006 4:56:28 PM org.apache.struts.util.PropertyMessageResources <init>

INFO: Initializing, config='org.apache.struts.taglib.bean.LocalStrings', returnNull=true

Aug 24, 2006 4:56:28 PM org.apache.struts.util.PropertyMessageResources <init>

INFO: Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true

Aug 24, 2006 4:56:33 PM org.apache.struts.util.PropertyMessageResources <init>

INFO: Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true

Aug 24, 2006 4:56:33 PM org.apache.struts.util.PropertyMessageResources <init>

INFO: Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true

Aug 24, 2006 4:56:33 PM org.apache.struts.util.PropertyMessageResources <init>

INFO: Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true

Aug 24, 2006 4:56:33 PM org.apache.struts.util.PropertyMessageResources <init>

INFO: Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true

Aug 24, 2006 4:56:33 PM org.apache.struts.util.PropertyMessageResources <init>

INFO: Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true

Aug 24, 2006 5:02:53 PM org.apache.catalina.core.StandardHostDeployer remove

INFO: Removing web application at context path /HelloWorld1

Aug 24, 2006 5:02:53 PM org.apache.catalina.core.StandardHostDeployer install

INFO: Processing Context configuration file URL file:C:\Program Files\Apache Software Foundation\Tomcat 5.0\conf\Catalina\localhost\HelloWorld1.xml

Aug 24, 2006 5:02:54 PM org.apache.catalina.startup.ContextConfig applicationConfig

INFO: Missing application web.xml, using defaults only StandardEngine[Catalina].StandardHost[localhost].StandardContext[/HelloWorld1]

Aug 24, 2006 5:06:23 PM org.apache.catalina.core.StandardHostDeployer remove

INFO: Removing web application at context path /HelloWorld1

Aug 24, 2006 5:07:53 PM org.apache.catalina.core.StandardHostDeployer install

INFO: Processing Context configuration file URL file:C:\Program Files\Apache Software Foundation\Tomcat 5.0\conf\Catalina\localhost\HelloWorld.xml

Aug 24, 2006 5:07:56 PM org.apache.catalina.startup.ContextConfig applicationConfig

INFO: Missing application web.xml, using defaults only StandardEngine[Catalina].StandardHost[localhost].StandardContext[/HelloWorld]

Aug 24, 2006 5:13:05 PM org.apache.catalina.core.StandardHostDeployer remove

INFO: Removing web application at context path /HelloWorld

Aug 24, 2006 5:13:05 PM org.apache.catalina.core.StandardHostDeployer install

INFO: Processing Context configuration file URL file:C:\Program Files\Apache Software Foundation\Tomcat 5.0\conf\Catalina\localhost\HelloWorld.xml

Aug 24, 2006 5:13:06 PM org.apache.catalina.startup.ContextConfig applicationConfig

INFO: Missing application web.xml, using defaults only StandardEngine[Catalina].StandardHost[localhost].StandardContext[/HelloWorld]

--

Also:

What about at this line

public class HelloWorldServlet extends HttpServlet {// Why is HelloWorldServlet underlined.

[5449 byte] By [Sanjeeta] at [2007-10-3 3:30:59]
# 1
i don't quite get what your problem is, but it could be a configuration prob.try to follow this. http://www.coreservlets.com/Apache-Tomcat-Tutorial/-Nywled
Redxxiva at 2007-7-14 21:24:58 > top of Java-index,Java Essentials,Java Programming...
# 2
It's OK. I've tried your code on Netbeans+SjasPE8
rick.qina at 2007-7-14 21:24:58 > top of Java-index,Java Essentials,Java Programming...
# 3
Ok I actually configuered it to run as a new java application. But when I ran it it gave m e the error message:java.lang.NoSuchMethodError: mainException in thread "main"
Sanjeeta at 2007-7-14 21:24:58 > top of Java-index,Java Essentials,Java Programming...
# 4
> Ok I actually configuered it to run as a new java> application. But when I ran it it gave m e the error> message:> > java.lang.NoSuchMethodError: main> Exception in thread "main"A servlet is NOT a standalone application.
ansi-boya at 2007-7-14 21:24:58 > top of Java-index,Java Essentials,Java Programming...
# 5
opps sorry, I am new to Java. Thanks for letting me know.When I typed in: http://localhost:8080/HelloWorld/hello on the browser the debog prespective opend and this is where it stopped: PrintWriter writer = response.getWriter();
Sanjeeta at 2007-7-14 21:24:58 > top of Java-index,Java Essentials,Java Programming...