The out variable isn’t the only implicit object...

When a Container translates the JSP into a servlet, the beginning of the service method is a pile of implicit object declarations and assignments.

With implicit objects, you can write a JSP knowing that your code is going to be part of a servlet. In other words, you can take advantage of your servletness, even though you’re not directly writing a servlet class yourself.

Think back to Chapter 4, Chapter 5, and Chapter 6. What were some of the important objects you used? How did your servlet get servlet init parameters? How did your servlet get context init parameters? How did your servlet get a session? How did your servlet get the parameters submitted by the client in a form?

These are just a few of the reasons your JSP might need to use some of what’s available to a servlet. All of the implicit objects map to something from the Servlet/JSP API. The request implicit object, for example, is a reference to the HttpServletRequest object passed to the service method by the Container.

image with no caption

Q:

Q: What’s the difference between a JspWriter and a PrintWriter I get from an HttpServletResponse?

A:

A: The JspWriter is not in the class hierarchy of PrintWriter, so you can’t use it in place of a PrintWriter. But it has most of the same print methods, except it adds some buffering capabilities.

Design Goal

Create a JSP that will produce this:

image with no caption

The HTML form

image with no caption

Note

Important tips and clues

  • The request attribute is of type java.util.ArrayList.

  • The implicit variable for the HttpServletRequest object is named request, and you can use it within scriptlets or expressions, but not within directives or declarations. Whatever you can do with a request object in a servlet, you do inside your JSP.

  • A JSP’s servlet method can process request parameters, because remember, your code is going to be inside a servlet’s service method. You don’t have to worry about which of the HTTP methods (GET or POST) was used in the request.

We’ve put a few lines in for you. The code you put in this JSP MUST work with the code that’s already here. When you’re done, it should be compilable and produce the result on the opposite page (you must ASSUME that there’s already a working servlet that first gets the request, sets the request attribute “names”, and forwards the request to this JSP).

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

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