next up previous contents
Next: Exercise 9: Remote Method Up: Lab 2: Guest book Previous: Exercise 7: Servlets

Exercise 8: Servlets with arguments

The previous exercise solved the problem of showing the entire HTML page, but it would also be nice to be able to show only some of the guests.

A servlet can take arguments, just like an applet or a CGI script. The arguments can be taken directly from an HTML form using the POST method, as follows:

<FORM METHOD=POST ACTION="/servlet/guestbook">
Name pattern to search for: <INPUT TYPE=text SIZE=40 NAME="namePattern"><p>
...and so on...
<INPUT TYPE="submit" VALUE="Query database">

When the user presses the button on the form, your servlet's doPost() method will be called. The method must do the following:



Jonas Kvarnstrom
2/5/1998