Cannot run 'HelloWorld' servlet in Tomcat environment

  • Thread starter the_JAVA_Rookie
  • Start date
T

the_JAVA_Rookie

I just tried my 1st servlet program, but still have some trouble in Tomcat,
can someone tell me what I missed?

I have two class files (HelloWorld.class and Hello.class) located @
C:\Tomcat\webapps\ROOT\WEB-INF\classes\,
and below is the contents of web.xml located @ C:\Tomcat\webapps\ROOT\WEB-INF\,

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">

<web-app>
<servlet>
<servlet-name>
hi
</servlet-name>
<servlet-class>
HelloWorld
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>
hi
</servlet-name>
<url-pattern>
/hello.html
</url-pattern>
</servlet-mapping>
</web-app>

when I typed this http://localhost:8080/servlet/HelloWorld in IE,
I got this error message:

HTTP Status 404 - /servlet/HelloWorld
 
W

Wendy S

the_JAVA_Rookie said:
<web-app>
<servlet>
<servlet-name>
hi
</servlet-name>
<servlet-class>
HelloWorld
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>
hi
</servlet-name>
<url-pattern>
/hello.html
</url-pattern>
</servlet-mapping>
</web-app>

when I typed this http://localhost:8080/servlet/HelloWorld in IE,
I got this error message:

HTTP Status 404 - /servlet/HelloWorld

You've mapped your servlet to the /hello.html URL pattern, so that's what
you need to use. Try http://localhost:8080/hello.html

Don't use the /servlet/ URL pattern, that was for the "invoker servlet"
which is now disabled by default. (Unfortunately, it *is* still enabled in
the examples webapp, causing no end of confusion for newbies.)
 
W

William Brogden

the_JAVA_Rookie said:
I just tried my 1st servlet program, but still have some trouble in Tomcat,
can someone tell me what I missed?

I have two class files (HelloWorld.class and Hello.class) located @
C:\Tomcat\webapps\ROOT\WEB-INF\classes\,
and below is the contents of web.xml located @ C:\Tomcat\webapps\ROOT\WEB-INF\,

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">

<web-app>
<servlet>
<servlet-name>
hi
</servlet-name>
<servlet-class>
HelloWorld
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>
hi
</servlet-name>
<url-pattern>
/hello.html
</url-pattern>
</servlet-mapping>
</web-app>

when I typed this http://localhost:8080/servlet/HelloWorld in IE,
I got this error message:

HTTP Status 404 - /servlet/HelloWorld
-------------------------------------------------------------------------- ------
type Status report
message /servlet/HelloWorld
description The requested resource (/servlet/HelloWorld) is not available.
-------------------------------------------------------------------------- ------
Apache Tomcat/4.1.27

by the way, those are examples from "Java Servlet Programming", 2nd edition.
Thanks in advance.

In Tomcat 4 the "invoker" servlet - that lets you use a url like
/servlet/HelloWorld
is no longer on by default. Look in the ../conf/web.xml for "invoker"

WBB
 
W

William Brogden

the_JAVA_Rookie said:
I just tried my 1st servlet program, but still have some trouble in Tomcat,
can someone tell me what I missed?

I have two class files (HelloWorld.class and Hello.class) located @
C:\Tomcat\webapps\ROOT\WEB-INF\classes\,
and below is the contents of web.xml located @ C:\Tomcat\webapps\ROOT\WEB-INF\,

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">

<web-app>
<servlet>
<servlet-name>
hi
</servlet-name>
<servlet-class>
HelloWorld
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>
hi
</servlet-name>
<url-pattern>
/hello.html
</url-pattern>
</servlet-mapping>
</web-app>

when I typed this http://localhost:8080/servlet/HelloWorld in IE,
I got this error message:

HTTP Status 404 - /servlet/HelloWorld
-------------------------------------------------------------------------- ------
type Status report
message /servlet/HelloWorld
description The requested resource (/servlet/HelloWorld) is not available.
-------------------------------------------------------------------------- ------
Apache Tomcat/4.1.27

by the way, those are examples from "Java Servlet Programming", 2nd edition.
Thanks in advance.

In Tomcat 4 the "invoker" servlet - that lets you use a url like
/servlet/HelloWorld
is no longer on by default. Look in the ../conf/web.xml for "invoker"

WBB
 
W

William Brogden

the_JAVA_Rookie said:
I just tried my 1st servlet program, but still have some trouble in Tomcat,
can someone tell me what I missed?

I have two class files (HelloWorld.class and Hello.class) located @
C:\Tomcat\webapps\ROOT\WEB-INF\classes\,
and below is the contents of web.xml located @ C:\Tomcat\webapps\ROOT\WEB-INF\,

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">

<web-app>
<servlet>
<servlet-name>
hi
</servlet-name>
<servlet-class>
HelloWorld
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>
hi
</servlet-name>
<url-pattern>
/hello.html
</url-pattern>
</servlet-mapping>
</web-app>

when I typed this http://localhost:8080/servlet/HelloWorld in IE,
I got this error message:

HTTP Status 404 - /servlet/HelloWorld
-------------------------------------------------------------------------- ------
type Status report
message /servlet/HelloWorld
description The requested resource (/servlet/HelloWorld) is not available.
-------------------------------------------------------------------------- ------
Apache Tomcat/4.1.27

by the way, those are examples from "Java Servlet Programming", 2nd edition.
Thanks in advance.


In Tomcat 4 the "invoker" servlet - that lets you use a url like
/servlet/HelloWorld
is no longer on by default. Look in the ../conf/web.xml for "invoker"

WBB
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top