JSP Directives


General syntax: <%@ directive attribute=”value” %>
Possible directives in the JSP are: page, include, taglib

PAGE DIRECTIVE:

(1) <%@ page info=”JSP page” %>
à Info on the page that can be accessed through Servlet.getServletInfo() method.
          Public String getServletInfo()
          {         return “JSP example”;
          }

(2) <%@ page language=”java” %>
à tells the server what language will be used in the file. Java is only supported for current specification.

(3) <%@ page import="java.applet.*, java.util.*" %>
à Specify java package and classes to be imported. It should always be placed at the top of the JSP file.

(4) <%@ page extends=”java.util.Dictionary” %>
à Normally, extends is not used because by default every class extends HttpJspBase. But if you do so HttpJspBase is replaced with java.util.Dictionary.

<%@ page implements=”java.util.Dictionary” %>
à It follows the same rule as extends. It is for interface.

(5) <%@ page buffer=”none/8kb/sizekb” %>
à Controls the size of the buffer associated with JspWriter. If you want unbuffered output, set it to none.
à By default, it is set to 8 KB. Use with autoflush.
          <%@ page buffer=”9kb” autoFlush=”true/false” %>
à If autoflush is “true”, it flushes the output buffer when it is full rather than araising an exception. Buffering improves the spped since it is better to write a large number of characters at the one go than a small number many times.

(6) <%@ page isThreadSafe=”true/false” %>
à If you want the servlets to create multiple instances of itself then you must give isThreadSafe=”false”. Default is true.
à By saying “false”, the JSP engine will implements SingleThreadModel interface and it can load multiple instances of servlets.
à If “true”, singles JSP engine that the multiple client requests can be dealt with at once. It is author’s job to synchronize shared state.

(7) <%@ page session=”true/false” %>
à By default session is true. True means session data is avaible. Implicit variable named session of type javax.servlet.http. HttpSession references current/new session for the page.
à false means that variable is not avaible.

(8) <%@ page contentType=”text/plain” %>
à By default it is “text/html”. This info must come early in the file before any non-Latin-1 characters appear in the file.