servlet 101 question

C

coltrane

I am attempting to write an HelloWorld servlet with tomcat and of
course I can't get it to work.
I am trying to run the first servlet from the CoreServlets book.
according to the book I can create a directory, place the servlet class
file, in the directory and invoke it in a browser. I compiled the
servlet and I placed it in a directory under the webapps directory.
Well of course this didn't work.
so where should I place the class file???.
btw, I was able to place a plain html file in the directory and get it
to run.

I am running tomcat 5.5 with winxp.

thanks for the help

john
 
C

coltrane

Okay, so I figured it out. I needed to create a web-inf directory and
use a web.xml file.
Strange this isn't mentioned for the first example in the book.

thanks
 
J

Juha Laiho

coltrane said:
Okay, so I figured it out. I needed to create a web-inf directory and
use a web.xml file.
Strange this isn't mentioned for the first example in the book.

Older versions of Tomcat (3.3 or so) did not require a WEB-INF/web.xml;
current ones (I think at least from 4.0 onwards) do. WEB-INF/web.xml is
a requirement of the servlet specification, so the current behaviour
is correct (even though it requires a bit more work).

I guess the Core Servlets book is written for Tomcat 3.3 (if so, it also
lacks information on some of the changes in later servlet specification
versions).
 
M

Mark Space

Juha said:
I guess the Core Servlets book is written for Tomcat 3.3 (if so, it also
lacks information on some of the changes in later servlet specification
versions).

Good point. O'Reilly's Head First Servlets and JSP has correct
information for deployment and other niceties. I found it very
accurate, and it has a lot of info too. If the OP wants to pick up a
more up-to-date book, I'd recommend HFSJ.
 
J

Juha Laiho

coltrane said:
thanks to both for the info.
I'm off to bookpool :)

Note also, that there are online resources to help you get started as well.

To get the basics on Tomcat, there is the "First Webapp" chapter
(http://tomcat.apache.org/tomcat-5.5-doc/appdev/index.html) in
the documentation. This'll guide through creating and deploying
a simple webapp, while also describing the basics of a typical
development environment.

Then, looking from the other side, the Java EE tutorials from Sun contain
good information on the different technologies, such as servlets, JSP
and so on;
http://java.sun.com/javaee/reference/tutorials/
especially
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/Overview7.html#wp79959
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/Overview7.html#wp79962
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top