Servlet classes

The servlet classes are included in the Enterprise Edition of the JDK, not the standard edition. The WebLogic and VisualAge tools should have this included; if you're using something else, you might need to fetch the relevant jars from here .

Using Servlets

In project 2, you'll implement your agent as a servlet. A servlet is a piece of Java code that is run by a web server and processes the result of an HTTP POST or GET, which is typically generated by a CGI form.

The good news is that you won't need to do anything too complicated with servlets for this project (although you certainly can if you like). Processing HTTP requests and returning XML and HTML documents will pretty much cover it.

Running servlets.

There are several Servlet engines available; for the project, it's not required that your agent be on the Web 24-7, although if you have access to your own web server, you might want to do this.

If you do have access to a server, you could consider any of the following servlet engines (this is not an exhaustive list - please point me to other solutions!)

If you don't have access to a web server, your best solution is probably to run Resin from your home directory. It's pretty straightforward to set up; just make sure you configure it to run on a port above 1024.

Examples

Here are some example servlets that you might want to take a look at:

A note on services: The code above implements the servlet using the service() method, which is invoked whenever a client sends a request message. An alternate approach, when subclassing httpServlet, is to implement the doGet() and doPost() methods, which are invoked by the default implementation of service().

Which to use? For this project, it's mostly a matter of taste. One advantage to implementing doGet() and/or doPost() is that it allows your servlet to advertise the sorts of HTTP requests it understands; once you implement one of these, your servlet automatically will be able to reply to an HTTP OPTIONS request and indicate which requests it can handle.

On the other hand, if you think you might decouple your servlet from HTTP and use it with some other protocol, then service() is the right thing to use.

References

Following is a list of references that might be helpful in implementing this project: