The Workshop is designed to help you review what you have learned and to help you to further increase your understanding of the material covered in this chapter.
Quiz
What are the names of the two objects discussed in this hour that are "built into" JSPs?
The getParameter method is used to obtain the value of a form variable. What object is this method part of?
Explain the difference between the doGet and doPost methods of HttpServlet.
Answers
-
Several objects are made available to JSPs. The two implicit objects that are discussed in this chapter are
-
.out, which provides a stream to write output content to.
-
.request, which is a reference to an instance of HttpRequest. It's used to access many of the attributes of the HTTP request that triggered the service invocation, including the names of any form names and values.
-
getParameter is a method of HttpRequest and is available through the request implicit object.
-
These methods are used to handle HTTP GET and POST request methods, respectively. The default implementation for either indicates that the method is not supported. You must override the methods in order to be able to work with the request types you are interested in handling.
Activities
Write an HTML form that includes a checkbox and other HTML form elements. Make the form use the GET request method. Write a JSP handler that returns the values for each element.
Change the form above to use the form POST method. Discover whether any changes are required to handle a POST. Look at the generated source code for the JSP.