Home > Articles

  • Print
  • + Share This
This chapter is from the book

Chapter Summary

The HTTP methods GET, POST, and PUT are how browsers and Web servers trade data with each other. The GET retrieves a page without providing much information, while a POST can package huge amounts of information with its request. A PUT is for uploading a file. There are events associated with each type of request, such as clicking a hyperlink sending a GET request, but clicking a form button sends a POST request.

The most important objects in the servlet process are the request and response objects. The request parameters for the servlet are the strings sent by the client to the Servlet Container. The container parses the request and puts the information in a HttpServletRequest object which is passed to the servlet. Going the other way, the container wraps the response parameters with the HttpServletResponse object which is passed back to the container.

Containers have the idea of scope. When something has Context scope it is application-wide and all users can share data. Session scope means one user can share data across page views, but other users can't. Request scope restricts data to only that page. The container also manages the servlet life-cycle by initializing a servlet with a call to the init() method, a call to the service() method upon every request, and by calling a servlet's destroy() method just prior to removing it from memory. The container also allows you to monitor context and session events with listeners that are event-driven triggers. When an attribute changes, special targeted methods are called. In them, you can define special actions such as "add a note to the log every time the user count changes."

Lastly, the servlet specifies a RequestDispatcher object which performs servlet forwarding. Notice that this is different from redirection, where the servlet would return a new URL to the browser that triggers the browser to try to get that page. The RequestDispatcher doesn't redirect; rather it "dispatches" or performs forwarding.


  • Redirection

  • Servlet Life-Cycle

  • Servlet Forwarding and Includes

  • Servlet attribute

  • Context parameters

  • Application session

  • listeners

  • + Share This
  • 🔖 Save To Your Account