Directives in jsp

Introduction of Directives -: In the JSP language directive play a very important role. It Gives directions and instructions to the JSP container.Directives have a number of attributes which we can list down as key-value pairs and separated by commas.There are the syntax of directives

<%@ directive attribute=”value” attribute=”value” ….%>

There are three type directives in jsp

directives in jsp

Page Directive in JSP-: This directive is used to provide instructions to the container. These instructions are related to the current JSP page. we can code page directives anywhere in your JSP page. Below the page, some attributes are used with Directive, those attributes are given.

AutoFlush: The buffer of JSP Page is used to flush automatically. If the buffer becomes full then it is flushed automatically. Its default value is ‘True’. The syntax of this <%@ page autoFlush=”value”%> for example <%@ page autoFlush=”True”%>

Buffer-: The buffer size is given in kilobytes at the value of the buffer attribute. The size of the default buffer is ‘8’. The size of buffer is also given as ‘none’. It handles the output stream. Syntax of buffer

<%@ page buffer=”value”%>

example of buffer

<%@ page buffer=”30kb”%>

Content Type-: content type sets the content type of the attribute page. These attribute MIME (Multipurpose Internet Mail Extension) type for JSP response.The syntax of content type

<%@ page contenttype=”value”%> example of content type <%@ page contenttype=”Text/html”%>

Error Page -: This is the set on this attribute. If an error occurs on the current page, the given page on the attribute is redirected.

<%@ page errorpage=”value”%> example of content type <%@ page errorpage=”error.jsp”%>

Extends -:this attribute defines the name of the Servlet class created from the JSP Page and the parent / super class inherited from it.

<%@ page extends=”value”%> example of content type <%@ page extends=”package.class”%>

Import -: This attribute is used to import the class, members and interface of the package. One or more packages on need. We can imported on the page using single attribute for this syntax of

<%@ page import=”value”%> example of content type <%@ page import=””%>

Info -: This attribute provide the information for JSP. The syntax of jsp is

<%@ page info=”value”%> example of content type <%@ page infor=”welcome in jsp page”%>

isELIgnored -:This attribute is used to ignore Expression Language (EL). This is the default. If ‘true’ is given then the Expression Language is ignored. The formula of using this attribute

<%@ page isELIgnored =”value”%> example of content type <%@ page isELIgnored =”True”%>

isErrorPage -This declare whether this attribute is current JSP page Errorpage or not. Its default value is ‘false’. for syntax of this

<%@ page isErrorpage =”value”%> example of content type <%@ page isErrorpage=”True”%>

isThreadSafe -: This attribute declares whether the JSP page is thread-safe or not. The value of this attribute is given as ‘true’ then the JSP page; Supports multi threading and if given ‘false’ then JSP page; Only one thread supports.

<%@ page isThreadSafe =”value”%> example of content type <%@ page isThreadSafe =”True”%>

Language -:This attribute is named after the scripting language used on the JSP page. The default value of this attribute is ‘java’. for example

<%@ page Language =”value”%> example of content type <%@ page Language =”Java”%>

page Encoding -: This attribute is the character encoding. In this, the JSP file is encoded to the given value. The default value of this attribute is ‘ISO-8859-1’. For example

<%@ page pageEncoding =”value”%> example of content type <%@ page pageEncoding =”UTF-8″%>

Session -: This attribute in the JSP page is used to handle the session. The default value of this attribute is ‘true’. This is a very important part of the session in JSP. The session is used for login and logout.for example

<%@ page Session =”value”%> example of content type <%@ page Session =”false”%>

include Directive in JSP

External files are included on the current JSP file with the help of include Directive. The external file is included when JSP Page is translated. JSP can include JSP, HTML and text file. Even in JSP, this directive is given. Wherever this directive is given, the code of the given external file is executed there. In JSP, an external file is included more than once. For syntax of this

<%@ include file=”external_file”%> example of content type <% Jsp:directives.include file =”external_file”/>

Taglib directive in jsp

taglib directive is used to use custom tags on the JSP page. More than one tag is defined in this tag library. The TLD (Tag Library Descriptor) file is used for those defined tags. taglib directive are divided in two part uri and perfix. Syntax for JSP taglib Directive

<%@ taglib uri=”uri_of_tag_library” prefix=”prefix_of_tag_library” %>

Leave a Comment