- Overriding HttpServlet GET, POST, and PUT Methods
- Triggering HttpServlet GET, POST, and PUT Methods
- Interfacing with HTML Requests
- Web Application Scope
- Servlet Life-cycle
- Using a RequestDispatcher
- Web Application Context
- Context Within a Distributable Web Application
- Chapter Summary
- Apply Your Knowledge
Triggering HttpServlet GET, POST, and PUT Methods
1.2 For each of the HTTP methods, GET, POST, and HEAD, identify triggers that might cause a browser to use the method, and identify benefits or functionality of the method.
This exam objective focuses on what triggers the events or methods in your servlets. For example, what action can a client take that results in the doGet() method being called in your servlet?
The benefits of the GET method are
It retrieves information such as a simple HTML page or the results of a database query.
It supports query strings (name-value pairs appended to URL). Servers usually limit query strings to about 1000 characters.
It allows bookmarks.
This occurs when a browser or application submits an HTML form with the method attribute set to post as in method=post.
The benefits of the POST method are
It sends information to the server such as form fields, large text bodies, and key-value pairs.
It hides form data because it isn't passed as a query string, but in the message body.
It sends unlimited length data as part of its HTTP request body.
It disallows bookmarks.
A browser or application will sometimes send a request to a server just to check the status or get information (for example, "can you handle file upload?") from the server.
The HEAD method returns the same header lines that a GET method would return; however, no body or content is returned. This is often accomplished by calling doGet(), setting the headers but not setting any output, and then returning the response (without any body) to the requester.
The primary benefit of this method is message size. The HEAD method receives and returns very small messages. Therefore it is fast and lightweight on both ends.