O'Reilly logo

Head First Servlets and JSP, 2nd Edition by Bert Bates, Bryan Basham, Kathy Sierra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Compiling, deploying, and testing the controller servlet

OK, we’ve built, deployed, and tested our HTML, and we’ve built and deployed our DD (well, we put the web.xml into the deployment environment, but technically the DD won’t be deployed until we restart Tomcat). Now it’s time to compile the first version of the servlet, deploy it, and test it via the HTML form. Now we’ll restart Tomcat to make sure that it “sees” the web.xml and servlet class.

Compiling the servlet

Compile the servlet with the -d flag to put the class in the development environment.

image with no caption

Deploying the servlet

To deploy the servlet, make a copy of the .class file and move it to the /Beer-v1/WEB-INF/classes/com/example/web/ directory in the deployment structure.

Testing the servlet

1 - Restart tomcat!

2 - Launch your browser and go to: http://localhost:8080/Beer-v1/form.html

image with no caption

4 - Select a beer color and hit “Submit”

5 - If your servlet is working, you should see the servlet’s response in your browser as something like:

image with no caption

Beer Selection Advice Got beer color brown

image with no caption

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required