Exercises

  1. Modify the petform servlet so that it includes the content length in its response.

  2. Write a servlet that sends back to the client (for display) all the parameters and HTTP request headers that it received. Have the servlet get enumerations of all the headers and all the parameters, and echo them back to the client.

  3. Write a JSP that handles our pet selection form.

  4. Earlier in this chapter, we showed an HTML form that invoked a servlet. It's actually possible to write a servlet or JSP that delivers that form as well as responding to it. When the servlet is invoked by a URL, it should respond with the HTML representing the form for pet selection. When the servlet is invoked by submitting the form, it should make the pet selection. That keeps everything relating to pet selection in one file, possibly easing maintenance. You can tell if a form was submitted by doing a requestParameter() on any of the argument names, like this: String formSent = request.getParameter("legs"). If the string comes back null, there wasn't a form submitted (or at least that argument was not filled in), so the servlet must have been invoked with a URL reference. The service routine should then generate the form. Otherwise, the servlet should send back the HTML with the pet selection. Write a JSP file so that it delivers the pet selection form in this way, and responds to it too.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.147.77