It is by no means complete or even the way you would want to write a timecard servlet. Astute programmers will notice some flaws in it immediately. However, it does give us an opportunity to play with some servlet features and, in so doing, learn a little. This one servlet generates two dynamic forms, processes both forms, generates a cookie, and stores the user's hours in a file on the server. All form generation is performed in the doGet method.
All form processing is performed in the doPost method.
When it doesn't find one, it creates a form allowing the user to enter his or her username. When the username is entered and the submit button pressed, the username will be submitted to the server. Normally, you would use a CGI script to process the form. However, one of the advantages of servlets is that they can generally do what a CGI script can do, and they can do it easier. In this case, in just a few lines in the doPost method, we create a cookie with the user's username, and then we redirect the user back to the same page.