Enhancing the servlet to “call” the JSP (version three)

In this step we’re going to modify the servlet to “call” the JSP to produce the output (view). The Container provides a mechanism called “request dispatching” that allows one Container-managed component to call another, and that’s what we’ll use—the servlet will get the info from the model, save it in the request object, then dispatch the request to the JSP.

The important changes we must make to the servlet:

1 - Add the model component’s answer to the request object, so that the JSP can access it. (Step 4)

2 - Ask the Container to forward the request to “result.jsp”. (Step 5)

image with no caption

1 - The browser sends the request data to the container.

2 - The Container finds the correct servlet based on the URL, and passes the request to the servlet.

3 - The servlet calls the BeerExpert for help.

4 - The expert class returns an answer, which the servlet adds to the request object.

5 - The servlet dispatches to the JSP.

6 - The JSP gets the answer from the request object.

7 - The JSP generates a page for the Container.

8 - The Container returns the page to the happy user.

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

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