Skip to content
  • Facebook
GeekCer Logo

GeekCer

The geek's Coding education and Review centre

  • Home
  • Tutorials
    • Java
    • Servlet
    • JSP
    • Python
    • C Tutorial
    • Spring
    • Spring Boot
    • MongoDB
    • Hibernate
    • Data Structure
  • General Knowledge
  • Biography
  • Grammar
  • Festival (त्योहार)
  • Interview
  • Differences
  • Important
  • Toggle search form

Home » JSP » JSP Directives

  • P V Sindhu Biography in Hindi
    P V Sindhu Biography in Hindi, Badminton, State, Caste पी. वी. सिंधु जीवन परिचय, कहानी, राज्य, जाति Biography
  • Subhas Chandra Bose Biography in Hindi, Essay, Paragraph
    Subhas Chandra Bose Biography in Hindi, Essay, Paragraph Biography
  • Ganesh Chaturthi Puja in Hindi | गणेश चतुर्थी का व्रत, महत्व, कथा
    Ganesh Chaturthi Puja in Hindi | गणेश चतुर्थी का व्रत, महत्व, कथा Festival
  • Amitabh Bachchan biography in hindi | Family, wife, awards
    Amitabh Bachchan biography in hindi | Family, wife, awards Biography
  • Vedaant Madhavan Biography in Hindi, Family, School, Age
    Vedaant Madhavan Biography in Hindi, Family, School, Age Biography
  • Kapil Sharma Show, Comedy Show in Hindi
    Kapil Sharma Show, Comedy Show in Hindi Biography
  • Human rights day
    Human rights day in Hindi: 10 दिसंबर ह्यूमन राइट्स डे General Knowledge
  • Vat Savitri Vrat in Hindi, Vat Savitri Puja | वट सावित्री पूजा
    Vat Savitri Vrat in Hindi, Vat Savitri Puja | वट सावित्री पूजा Festival

JSP Directives

Posted on September 1, 2021October 20, 2021 By GeekCer Education No Comments on JSP Directives
JSP Directives

JSP Directives are elements of a JSP source code that instruct the server how to process a page.

Table of Contents

    • Types of JSP Directives
    • Syntax of JSP Directives
  • JSP Directives – Page, Include and TagLib
  • JSP Page Directive
    • Syntax of Page Directive
    • Important Attributes of Page Directive
      • autoFlush Attribute
      • buffer Attribute
      • contentType Attribute
      • errorPage Attribute
      • extends Attribute
      • import Attribute
      • info Attribute
      • isELIgnored Attribute
      • isErrorPage Attribute
      • session Attribute
      • pageEncoding Attribute
      • language Attribute
      • isThreadSafe Attribute
  • JSP Include Directive
    • Syntax of Include Directive
  • JSP Taglib Directive
    • Syntax of Taglib Directive

Types of JSP Directives

There are following types of JSP directives:

  • Page Directive
  • Include Directive
  • Taglib Directive

Syntax of JSP Directives

<%@ directive attribute = "value"%>

JSP Directives – Page, Include and TagLib

Let us discuss about JSP directives one by one with syntax and give examples for each directive. In this section we discuss the basic concept of page, includes and taglib directive and attributes of page directive.

JSP Page Directive

The page directive lets you control the structure of the servlet by importing classes, customizing the servlet superclass, setting the content type and so on.

You can use a page directive can be placed anywhere within the document. Page directive provides instructions to a container, the container applies the instruction to the whole JSP.

Syntax of Page Directive

<%@ page [attribute-list] %>

<%@ page attribute = "value" %>

Important Attributes of Page Directive

There are following attributes of page directive:

  1. autoFlush
  2. buffer
  3. contentType
  4. errorPage
  5. extends
  6. import
  7. info
  8. isELIgnored
  9. isErrorPage
  10. isThreadSafe
  11. language
  12. pageEncoding
  13. session

autoFlush Attribute

When the output buffer is full it should be flushed automatically or if the buffer overflows it should raise an exception. The autoflush attribute handles such cases. In other words, autoFlush controls the behavior of the servlet output buffer. By default autoFlush=”true”.

<%@ page autoFlush="true/false" %>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" autoFlush="false" %>

buffer Attribute

The buffer attribute specifies the size of the buffer that the out variable uses, which is of type JspWriter. Servers can use a larger buffer than you specify, but not a smaller one.

By using buffer attribute you can define the size of buffering and default size is 8KB.

<%@ page page buffer="sizekb" %>

<%@ page page buffer="none" %>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" buffer="16KB" %>

contentType Attribute

The ContentType attribute sets the Content-Type response header, which indicates the MIME type of the document the client is receiving.

<%@ page contentType="MIME-Type" %>
<%@ page contentType="MIME-Type; charset=Character-Set" %>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" %>

errorPage Attribute

We use the errorPage attribute to define the error page, it helps to redirect to the error page when there is an exception on the page.

<%@ page errorPage="Relative URL" %>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" errorPage="page.jsp" %>

extends Attribute

You can use extends attribute to extend (inherit) the class similar as Java does.

<%@ page extends="package.class" %>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="java.util.*" %> 

import Attribute

We use import attribute to import class, interface or all the members of a package.

<%@ page import="package.class" %>

<%@ page import="package.class1,...,package.classN" %>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="java.util.*" %> 

info Attribute

The info attribute defines a string that you can retrieve it from the servlet and you can have a ServletInfo() method to access it.

<%@ page info="Some Message" %>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" info="Welcome to Geekcer!" %> 

isELIgnored Attribute

The isELIgnored attribute handles cases when you need to manage whether to ignore or evaluate JSP 2.0 Expression Language (EL) in general.

<%@ page isELIgnored="true/false" %>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" isELIgnored="false" %> 

isErrorPage Attribute

The isErrorPage attribute indicates whether the current page can act as an error page for another JSP page.

<%@ page isErrorPage="true/false" %>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" isErrorPage="true" %> 

session Attribute

If you want the page to participate in an HTTP session, you should use the session attribute. By default session = “true”.

<%@ page session="true/false" %>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
     pageEncoding="ISO-8859-1" session="false" %> 

pageEncoding Attribute

The pageEncoding attribute defines the character encoding for JSP page.

<%@ page pageEncoding="value" %>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
     pageEncoding="ISO-8859-1" %> 

language Attribute

The language attribute specifies the scripting language which we use in JSP page.

<%@ page language="language-name" %>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" language="java" %> 

isThreadSafe Attribute

The isThreadSafe attribute defines the thread safety in the page. By default isThreadSafe=”true”.

<%@ page isThreadSafe="true/false" %>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" isThreadSafe="false" %> 

JSP Include Directive

You can include directive when you need to insert file in JSP page. The file content can be a JSP file, an HTML file, or a text file.

You should include the file at the point in which you want the file.

Syntax of Include Directive

<%@ include file="resource-Name" %>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<%@ include file="header.html" % >



<%@ include file="footer.html" % >

</body>
</html>

JSP Taglib Directive

By using Taglib directive you can use your user defined tag library into the JSP page. It uses a set of custom tags, identifies the location of the library.

Syntax of Taglib Directive

<%@ uri="uri" prefix="value" %>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib uri="https://geekcer.com/" prefix="geekTag" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

</body>
</html>

Share this:

  • Click to share on Facebook (Opens in new window)
  • Click to share on WhatsApp (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • More
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Pinterest (Opens in new window)

Also Read

JSP

Post navigation

Previous Post: JSP Scripting Tags (Scripting Elements)
Next Post: JSP Implicit Objects

More Related Articles

Java Server Pages (JSP) Java Server Pages (JSP) JSP
HTTP status codes List | Response Status Code Glossary HTTP status codes List | Response Status Code Glossary Important
JSP Scripting Tags (Scripting Elements) JSP Scripting Tags (Scripting Elements) JSP
JSP Implicit Objects JSP Implicit Objects JSP

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • JSP Home
  • JSP Scripting Tags
  • JSP Directives
  • JSP Implicit Objects
  • National Farmers Day in Hindi | राष्ट्रीय किसान दिवस पर निबंध | चौधरी चरण सिंह जयंती
  • Human rights day in Hindi: 10 दिसंबर ह्यूमन राइट्स डे
  • Unicef day is celebrated on December 11 | Speech on unicef day
  • Indian Navy Day: जल सेना दिवस कब और क्यों मनाया जाता है?
  • P V Sindhu Biography in Hindi, Badminton, State, Caste पी. वी. सिंधु जीवन परिचय, कहानी, राज्य, जाति
  • Draupadi Murmu Biography In Hindi | द्रौपदी मुर्मू की जीवनी
  • TCP/IP Model, Full Form, Layers and their Functions
    TCP/IP Model, Full Form, Layers and their Functions Networking
  • Difference between Internet and Intranet
    Difference between Internet and Intranet Differences
  • Difference between TCP and UDP
    Difference between TCP and UDP | TCP vs UDP examples Differences
  • Network kya hai (नेटवर्क क्या है)
    Network kya hai (नेटवर्क क्या है) Networking
  • Similarities and difference between OSI and TCP/IP model
    OSI vs TCP/IP Model, Similarities and difference between OSI and TCP/IP model Networking
  • OSI Model | 7 Layers of OSI Model in Computer network
    OSI Model | 7 Layers of OSI Model in Computer network, Functions Networking
  • IPv4 Vs IPv6 | Difference between IPv4 and IPv6
    IPv4 Vs IPv6 | Difference between IPv4 and IPv6 Differences
  • Java Tutorial
  • Servlet Tutorial
  • JSP Tutorial
  • Maven Tutorial
  • HTML Tutorial
  • Programs
  • Hindi/English Grammar
  • Difference Between ... and ...
  • HR Interview
  • Important Articles

Write to Us:
geekcer.code@gmail.com

  • About Us
  • Privacy and Policy
  • Disclaimer
  • Contact Us
  • Sitemap

Copyright © GeekCer 2022 All Rights reserved