Servlets Demystified (write, deploy, run)
Just so those new to servlets can stop holding their breath, here’s a quick guide to writing, deploying, and running a servlet. This might create more questions than it answers—don’t panic, you don’t have to do this right now. It’s just a quick demonstration for those who can’t wait. The next chapter includes a more thorough tutorial.
Build this directory tree (somewhere not under tomcat).

Write a servlet named Ch1Servlet.java and put it in the src directory (to keep this example simple, we aren’t putting the servlet in a package, but after this, all other servlet examples in the book will be in packages).

Create a deployment descriptor (DD) named web.xml, put it in the etc directory

Build this directory tree under the existing tomcat directory...
From the project1 directory, compile the servlet...

(the Ch1Servlet.class file will end up in project1/classes)
Copy the Ch1Servlet.class file to WEB-INF/classes, and copy the web.xml file to WEB-INF.

From the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access