[ Team LiB ] Previous Section Next Section

Workshop

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

Quiz

1:

What are some of the effects of including a resource at compile time or run time?

2:

What is jspf?

3:

What class is used by servlets to include or forward to a resource?

4:

If you want the client of a page to see the output of a resource that forwards to another, what can you do?


Answers

A1:

Resources that are included at compile time produce a compound resource that is used at runtime. The one becomes a part of the other. There may be a performance advantage since the runtime component is "prepared beforehand." Resources that are included at compile time cause the result of their evaluation at runtime to become a part of the output of the other. The most important effect of this is that the resources included at runtime are more limited—for example, they cannot set headers. However, this combination is often more flexible, since the included file can also be determine at runtime. Beyond simply selecting the resource at runtime, you can also mix servlets and JSPs.

A2:

jspf is an extension used with jsp segments, which are syntactically the same as a JSP, but are designed for inclusion as a type of component.

A3:

A RequestDispatcher is used for both operations. You use its include and forward methods.

A4:

Recall that forwarding to another resource causes the output buffer to be cleared. In most cases, this is desireable. If you want the client to see the output of the first page, flush the buffer prior to forwarding.


Activities

  1. Write a JSP that includes another JSP at runtime. Pass a dynamic parameter such as the current time between the two. Display the parameter in the included page. Do this once using scriptlets or declarations and the other time without.

  2. Repeat the previous exercise, substituting a servlet for the first JSP.

    [ Team LiB ] Previous Section Next Section