A.11. The JSP page Directive: Structuring Generated Servlets

The import Attribute

  • <%@ page import="package.class" %>

  • <%@ page import="package.class1,...,package.classN" %>

The contentType Attribute

  • <%@ page contentType="MIME-Type" %>

  • <%@ page contentType="MIME-Type; charset=Character-Set" %>

  • Cannot be invoked conditionally. Use <% response.setContentType("..."); %> for that.

Example of Using contentType

Excel.jsp
<%@ page contentType="application/vnd.ms-excel" %>
<%-- Note that there are tabs, not spaces, between columns. --%>
1997   1998   1999   2000   2001 (Anticipated)
12.3   13.4   14.5   15.6   16.7

Example of Using setContentType

 ApplesAndOranges.jsp <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <!-- HEAD part removed. --> <BODY><CENTER><H2>Comparing ...

Get Core Servlets and JavaServer Pages™ 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.