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

While we’re on the subject... let’s talk more about the three directives

We already looked at the directive used for getting import statements into the generated servlet class made from your JSP. That was a page directive (one of the three directive types) with an import attribute (one of 13 attributes of the page directive). We’ll take a quick look now at the others, although some won’t be covered in detail until later chapters, and some won’t be covered in detail at all in this book, because they’re rarely used.

  1. The page directive

    <%@ page import="foo.*" session="false" %>

    Defines page-specific properties such as character encoding, the content type for this page’s response, and whether this page should have the implicit session object. A page directive can use up to thirteen different attributes (like the import attribute), although only four attributes are covered on the exam.

  2. The taglib directive

    <%@ taglib tagdir="/WEB-INF/tags/cool" prefix="cool" %>

    Defines tag libraries available to the JSP. We haven’t talked about using custom tags and standard actions yet, so this might not make any sense at this point. Just go with it for now...we have two whole chapters on tag libraries coming up soon.

  3. The include directive

    <%@ include file="wickedHeader.html" %>

    Defines text and code that gets added into the current page at translation time. This lets you build reusable chunks (like a standard page heading or navigation bar) that can be added to each page without having to duplicate all that ...

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