O'Reilly logo

Head First Servlets and JSP, 2nd Edition by Bert Bates, Bryan Basham, Kathy Sierra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.)

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required