str.append("The width is ");
str.append(" and the height is ");
// write output to the response object
PrintWriter out = res.getWriter();
The service() method (here called doGet() ) always has two arguments, which are an input and
an output object. For an HTTP servlet, those objects are the HTTP request and the HTTP
response. The HTTP request object passes all arguments to the servlet that were received by
the Web server with the request. The response object contains a PrintWriter stream to hold the
response that is generated by the servlet.
The simple servlet shown above reads two parameters width and height from the request
object. Then, it draws a rectangle of these dimensions to a string buffer. Finally, it writes the
string buffer containing the rectangle to the response object.
While this servlet does not seem particularly useful, and the same functionality could be
achieved through some browser side scripting, it does already show some of the servlet
architecture's power: The doGet() method uses fill(char[ ] a, char val) of the Java Arrays
package. All of Java's extensive library packages can be accessed through servlets, as well as
any other classes or methods available on the server (custom classes, J2EE beans, etc.).