This chapter presents focused discussions of topics related to creating responses from a servlet. The organization of this chapter loosely follows the typical order in which a servlet creates a response. The chapter describes each topic in isolation. See
Chapter 9, Creating Servlets, for an example of a complete servlet.
Servlets that rely on maintaining state between requests most often let the servlet container manage state using sessions (
Saving Session State). A servlet creates HTTP headers for the response (
Creating HTTP Headers). The servlet may create the content of the response directly (
Creating an HTTP Response). If the servlet generates HTML, the response may contain a URL back to the servlet (
Creating an HTTP Response). If the servlet cannot fulfill the request, the servlet returns an HTTP error (
Returning an Error), redirects the client (
Redirecting the Client), or obtains the response from another servlet in the servlet container or another location on the Web (
Forwarding a Request).
This section follows the conventions that
request is a
rwsf::HttpServletRequest object, that
response is a
rwsf::HttpServletResponse object and that any standalone lines of code occur within a servlet function such as
doPost().