JSP Page Directive
JSP directives are elements which transmit messages to the JSP container and directs how it compiles the JSP page. However, it is to note that the directives themselves do not appear in the XML output.
There are three types of directives:
- page directive
- include directive
- taglib directive
Page Directive
Page directive element defines a number of page related properties and communicates these to the JSP container.
Syntax of page directive
<%@ page attribute="attribute-value" %>
Page directive attributes
Following is the list of attributes of page directive
- import
- info
- contentType
- extends
- buffer
- isThreadSafe
- isELIgnored
- language
- autoFlush
- session
- pageEncoding
- errorPage
- isErrorPage
Import
As the name suggests, it is used to import any java class, interface, abstract class or all together.
<%@ page import="java.util.Random"%>
<html>
<body>
Random Number :
<% Random r = new Random();
out.println(r.nextInt(10)); %>
</body>
</html>
- buffer: Buffer attribute sets the buffer size in KB to control the JSP page’s output.
- contentType: The ContentType attribute defines the document’s MIME (Multipurpose Internet Mail Extension) in the HTTP response header.
- autoFlush: The autoFlush attribute controls the behavior of the servlet output buffer. It monitors the buffer output and specifies whether the filled buffer output should be flushed automatically or an exception should be raised to indicate buffer overflow.
- errorPage: errorPage defines a page to which current page will redirect to in case of exception. If an exception occurs on the current page, it will be redirected to the error page.
- extends: extends attribute used for specifying a superclass that tells whether the generated servlet has to extend or not.
- isErrorPage: this attribute of the Page directive is used to specify that the current page can be used as an error page.
- info: this attribute sets the JSP page information, which is later obtained using the getServletInfo() method of the servlet interface.
- isThreadSafe: Both the servlet and JSP are multithreaded. If you want to control JSP page behavior and define the threading model, you can use the isThreadSafe attribute of the page directive. It can have true or false value.
- Language: The language attribute specifies the programming language used in the JSP page. The default value of the language attribute is “Java”.
- Session: In JSP, the page directive session attribute specifies whether the current JSP page participates in the current HTTP session.
- isELIgnored: This isELIgnored attribute is used to specify whether the expression language (EL) implied by the JSP page will be ignored.
- isScriptingEnabled: this attribute determines if the scripting elements are allowed to be used or not.