1 / 14

Servlet Structure Control: Page Directive and Import Attribute

Learn how to control the structure of generated servlets in JSP using the page directive and import attribute. Import classes, customize superclass, set content type, and more.

shanac
Download Presentation

Servlet Structure Control: Page Directive and Import Attribute

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 12 Controlling the Structure of Generated Servlets: The JSP page Directive

  2. Chapter 12 • There are three main types of directives: page, include, and taglib. • The page directive control the structure of the servlet by importing classes, customizing the servlet superclass, setting the content type, and the like • include insert a file into the JSP page at the time the JSP file is translated into a servlet • taglib, defines custom markup tags

  3. The import Attribute • The import attribute of the page directive specifies the packages that should be imported by the servlet into which the JSP page gets translated • <%@ page import="java.util.*" %> • Listing 12.1 ImportAttribute.jsp

  4. The contentType and pageEncoding Attributes • The contentType attribute sets the Content-Type response header • <%@ page contentType="application/vnd.ms-excel" %> • Conditionally Generating Excel Spreadsheets (Section 3)

  5. The session Attribute • The session attribute controls whether the page participates in HTTP sessions. • <%@ page session="true" %> • <%@ page session="false" %>

  6. The buffer and autoFlush Attributes • The buffer attribute specifies the size of the buffer used by the out variable . • Use of this attribute takes one of two forms: • <%@ page buffer="sizekb" %> • <%@ page buffer="none" %>

  7. The buffer and autoFlush Attributes • The autoFlush attribute controls whether the output buffer should be automatically flushed when it is full . • two forms. • <%@ page autoFlush="true" %> • <%@ page autoFlush="false" %>

  8. The errorPage and isErrorPage Attributes • The errorPage attribute specifies a JSP page that should process any exceptions • <%@ page errorPage="Relative URL" %>

  9. The errorPage and isErrorPage Attributes • The isErrorPage attribute indicates whether or not the current page can act as the error page for another JSP page. • Use of isErrorPage takes one of the following two forms: • <%@ page isErrorPage="true" %> • <%@ page isErrorPage="false" %>

  10. Practice Exercises Exercise 1 Create an JSP page allow user enter full name. Display First name, last name, middle name. Use: java.util.StringTokenizer

  11. Exercise 1 - Interface

  12. Exercise 2 <% response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-disposition","attachment;filename=" + classname + ".xls"); %> Sample export to excel file

  13. Create sample list of students in a class. Create link to export the list of students in excel file format.

  14. Exercise 3 • Use <%@ page errorPage="errormessage.jsp" %> <%@ page isErrorPage="true" %> Design generalErrorPage of your website

More Related