Show TOC Start of Content Area

Procedure documentation Using the page Directive  Locate the document in its SAP Library structure

Use

With the page directive, you can define various properties that are global for the current JSP page. This includes making import statements of the classes that the JSP uses, setting the content type of the response that the page generates, specifying the content encoding of the page, controlling the size and the flushing of the response buffer, specifying whether the page requires a session, and so on.

Procedure

Importing Classes into a JSP

You import classes to be used by your JSP page using the import attribute of the page directive. Since you may need to import multiple classes, you can specify multiple values for the attribute.

Syntax

You import two Java utility classes, the LocationModel enterprise bean class, and another class that defines constants that are used in the application with this page directive:

<%@ page import = "java.util.Collection, java.util.Iterator,   com.sap.engine.examples.epf.ejb.common.LocationModel, com.sap.engine.examples.epf.Constants" %>

Setting Content Type and Content Encoding

Use the contentType attribute of the page directive to set the content type of the response message. If you do not use the attribute at all, the response messages that your JSP page generates will be of type text/html. The result of this directive will be the same as the result of the setContentType() method of the response object in servlets.

You can also specify the character encoding to be applied to the JSP page by specifying a character set as value of the contentType attribute.

Note

The content type that you specify is applied to the current JSP page, as well as any other JSP page that you have included in it.

Managing the Response Buffer

You can specify whether or not you want your JSP to buffer output, as well as set the size of the buffer if you use one. To do this, use the buffer attribute of the page directive. If you use buffering, you can use the autoflush attribute of this directive to control the flushing behavior of the buffer. The default behavior is that the buffer is flushed automatically when it becomes full.

Using HTTP Sessions in a JSP Page

You can specify that your JSP page does not require HTTP sessions by setting the session attribute of the page directive to false. The default value of this attribute is true, which means that the implicit session variable is bound to the session of the client (if such a session exists); if no session exists on the server, a new one is created and bound to the session variable. If the value is false, session variable will not be created and any attempt to use it will result in compilation error.

Note

All programming guidelines concerning HTTP sessions that are described in Creating Servlets must also be observed when developing session-aware JSP pages.

Specifying Error Pages to Process Exceptions

Use the errorPage attribute of the page directive to set the URL to the page that will be returned to the client if an exception occurs, and it is not caught in the current JSP page.

For more information about all attributes of the page directive and their values, refer to the Java Server Pages(TM) Specification at http://java.sun.com.

Disabling Expression language

If the isELIgnored attribute is set to true, then EL evaluation in this page is disabled. If ${} and #{} patterns are met in the JSP page they are accepted as a plain text. You could use this for preserving backward compatibility when JSP 1.2 compatible application uses EL syntax unintentionally.

No Errors for Deferred Syntax in the Template Text

When deferred EL is met in template text the JSP specification mandates that translation time error should be thrown. However, for keeping backward compatible behavior, a JSP 1.2 or JSP 2.0 compatible application that uses deferred syntax in template text could set the  deferredSyntaxAllowedAsLiteral attribute of the page directive to true and then the deferred expressions will be accepted as template text.

Trimming Whitespaces in the Template Text

If the trimDirectiveWhitespaces attribute of the page directive is set to true then a template text element that contains only whitespace is ignored and is not added to the output.

Example

A template text element is, for example, the characters between two directives:

<%@ taglib prefix="x" uri="http://com.sap.jsp/my.tld" %>

<%@ page import="java.util.*, java.io.*" %>

If trimDirectiveWhitespaces is set to false (the default value) then new line is inserted in the output.

The attribute is ignored by JSP documents.

 

 

End of Content Area