Step 14- JSP DIRECTIVES

DirectivePurposeSyntax
pageSets various attributes for the JSP page, such as content type, error page, session tracking, etc.<%@ page attribute1=”value1″ attribute2=”value2″ %>
includeIncludes the content of another file in the current JSP file<%@ include file="filename" %>
taglibIncludes a tag library in the JSP page<%@ taglib uri="taglibrary-uri" prefix="tag-prefix" %>

1- page directives

JSP-Page-Directive-attributes-450x268
DirectivesDescription
<%@ page language="java" %>Specifies the programming language used in the JSP page.
<%@ page import="java.util.*" %>Imports classes from the Java package.
<%@ page contentType="text/html" %>Specifies the MIME type of the response.
<%@ page session="true" %>Indicates whether the page participates in a session.
<%@ page buffer="8kb" %>Specifies the buffer size for the response.
<%@ page errorPage="error.jsp" %>Specifies the error page to which the client is redirected if an error occurs.
<%@ page isErrorPage="true" %>Indicates that the current page is an error page.
<%@ page extends="package.class" %>Specifies the superclass for the generated servlet.
<%@ page info="info" %>Provides a string that can be accessed with the ServletInfo interface.
<%@ page isThreadSafe="true" %>Indicates whether the generated servlet can handle multiple requests simultaneously.
<%@ page pageEncoding="UTF-8" %>Specifies the character encoding for the JSP page.
<%@ page autoFlush="true" %>Indicates whether the buffer should be automatically flushed when it is full.
<%@ page trimDirectiveWhitespaces="true" %>Determines whether whitespace should be removed from template text in a JSP page.
<%@ page deferredSyntaxAllowedAsLiteral="true" %>Allows the use of expressions that are deferred until the time they are used.
<%@ page scriptingInvalid="true" %>Indicates that the JSP page contains scriptlets.
<%@ page includePrelude="" %>Includes a file at the beginning of the servlet generated from a JSP page.
<%@ page includeCoda="" %>Includes a file at the end of the servlet generated from a JSP page.
<%@ page errorOnUndeclaredNamespace="true" %>Indicates whether an error should be raised if a JSP page uses a tag from an undeclared tag library.
<%@ page cbuffering="true" %>Indicates whether the output should be buffered for the JSP page.
<%@ page import="java.io.*" %>Imports classes from the Java package
<%@ page bufferSize="8kb" %>Specifies the buffer size for the response
<%@ page isELIgnored="true/false" %>Indicates whether or not the Expression Language is ignored.

2- include directives

JSP include directive is used to include the contents of another file to the current JSP page. The included file can be HTML, JSP, text files etc.

<%@ include file=”test.html” %>

3- taglib directives

<%@ taglib uri=”/WEB-INF/c.tld” prefix=”c”%>

JSP taglib directive is used to define a tag library with prefix that we can use in JSP.

note-other prefixes are c,fmt,sql,x,fn