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

Get Head First Servlets and JSP, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.