[ Team LiB ] Previous Section Next Section


The Workshop is designed to help you review what you have learned and help you to further increase your understanding of the material covered in this hour.



How do you get to the raw content of a request?


When is the content of a response buffer sent to a client?


What are a few common methods used to identify sessions?



You can get the body of a request by using the getReader or getInputStream methods of a request object. There's no way provided by the servlet request objects to obtain the raw HTTP request. Fortunately, you will never need to access this information directly in a Web application, since ServletRequest and HttpServletRequest make the parsed information easily available.


A number of activities can cause the content of a buffer to be sent. In most cases, the service method ends or the amount of content specified by setContentLength has been written to the buffer. The container will also send the content when the buffer is filled or when the method flushBuffer is called. Finally, the content of a buffer will be sent if the sendError or sendRedirect methods of the response object are invoked.


Sessions are commonly identified through the use of cookies or by adding a session ID to the URL. However, containers are free to implement other methods as well. For example, when using SSL as part of HTTPS, a container can use the session information provided by SSL.


  1. Write a servlet that displays all of the information about an HttpServletRequest.

  2. Create a simple servlet that receives a username from a form, stores the name in a context attribute and forwards to another servlet that displays the name.

  3. Create a simple servlet that stores a username as part of a cookie. Write a companion servlet that displays the username retrieved from the cookie.

    [ Team LiB ] Previous Section Next Section