Use the page directive to import packages

A directive is a way for you to give special instructions to the Container at page translation time. Directives come in three flavors: page, include, and taglib. We’ll look at the include and taglib directives in later chapters, but for now all we care about is the page directive, because it’s the one that lets you import.

image with no caption

To import a single package:

image with no caption

To import multiple packages:

image with no caption

Notice what’s different between the Java code that prints the counter and the page directive?

The Java code is between angle brackets with percent signs: <% and %>. But the directive adds an additional character to the start of the element—the @ sign!

If you see JSP code that starts with <%@, you know it’s a directive. (We’ll get into more details about the page directive later in the book.)

Get Head First Servlets and JSP, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.