Exercises Servlet Basics
Exercises Servlet Basics
Make a new Eclipse project called exercises-basics (or some such). Note that my solutions are in the project called basics-exercises. For this and all other exercises in the course, we will review the solutions before starting the next lecture. But you can always peek at my solutions ahead of time if you want.
1.
Make a package called servletBasics (or some other name of your choosing) and copy TestServlet from your previous project. Note that if you copy from the testServlet package (which is what I happened to name the package in the test-app project) and paste into some other package, Eclipse will automatically fix the package statement for you. Modify it so that it says Hello Your-Name. Deploy the application and run the new servlet. (http://localhost/your-project-name/your-addressfrom-the-WebServlet-annotation) You do not need to use my ServletUtilities class, but if you want to, either copy ServletUtilities to the servletBasics directory and change package coreservlets to package yourPackage, or (better!) leave it in the coreservlets directory and add import coreservlets.* to whichever of your servlets uses ServletUtilities. I think it is better at the beginning to skip ServletUtilities and make your servlets self-contained.
2.
Create a servlet that makes a bulleted list of four random numbers. I find it easier and better to copy and rename an existing servlet like TestServlet than to do New Servlet in Eclipse, but you can try it both ways and see which you like better. Reminder 1: you use Math.random() to output a random number in Java. Reminder 2: you make a bulleted list in HTML 4 as follows <UL> <LI>List item 1 <LI>List item 2 ... </UL> (In xhtml, you should use lower case and include the </li> tags.)
3.
Create a servlet that uses a loop to output an HTML table with 25 rows and 10 columns. For instance, each row could contain RowX, Col1, RowX Col2, and RowX Col3, where X is the current row number. If you dont know the HTML syntax for tables, please ask me.
http://www.coreservlets.com