[ Team LiB ] Previous Section Next Section


The Workshop is designed to help you review what you have learned, and help you to further increase your understanding of the material covered in this chapter.



Which implicit object can be used to get request parameters?


Which built-in objects are specific to JSPs?


How do you save and retrieve an object for use during the lifecycle of a request?



The request object is an instance of HttpServletRequest, which provides methods such as getParameter that can be used to obtain parameter values. Remember that most of the implicit objects are instances of classes that implement a core Java technology or the servlet API.


page, pageContext, and out are all instances of classes that are unique to JSPs—they are not defined in the servlet API. As a developer, you will need to be aware of the differences between out, which is a JspWriter, and the Printwriter returned by the getWriter method of a ServletResponse. In essence, you will need to remember that several methods of the JspWriter throw exceptions. Similar methods in a PrintWriter do not. In addition, a JspWriter may provide additional flexibility because of extended buffer control. For example, in spite of the fact that template text may have been buffered to output, you can often still set HTTP header information, because a response has not yet been sent.


You can use the pageContext implicit object. The method setAttribute with a scope parameter of PageContext.REQUEST_SCOPE will store an object so that it can be accessed by any resource servicing a request. The corresponding method getAttribute with the same scope parameter or findAttribute is used to retrieve the object.


Write a JSP that stores objects in each of the scopes. Cause the JSP you have written to also forward to DumpAttributes.jsp and verify that the objects you saved are in the proper scope.

    [ Team LiB ] Previous Section Next Section