

{"id":81366,"date":"2020-08-31T09:00:41","date_gmt":"2020-08-31T03:30:41","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=81366"},"modified":"2021-08-25T13:47:32","modified_gmt":"2021-08-25T08:17:32","slug":"jsp-directives","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/jsp-directives\/","title":{"rendered":"JSP Directives &#8211; Page, Include and Taglib Directives"},"content":{"rendered":"<p>Welcome to DataFlair\u00a0 JSP Directives Tutorial. This article discusses the directives used in JSP. It tells about the attribute used in detail along with their syntax. So let us start!!!<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Directives.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81390\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Directives.jpg\" alt=\"JSP Directives\" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Directives.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Directives-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Directives-1024x536.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Directives-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Directives-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Directives-520x272.jpg 520w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><\/p>\n<h2>JSP Directives<\/h2>\n<p>A page must contain every single line of code necessary for processing the request. But that is not all. Some instructions need to be given to the compiler on how to execute that written code. For this what we require is directives.<\/p>\n<p>Directives are written in these &lt;%@__%&gt; tags. Directives gives the information about the complete JSP page. JSP gets converted to servlet code during the translation phase, and these directives are messages or instructions to that JSP container on how to handle the request generated.<\/p>\n<p><strong>Syntax:\u00a0<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ directive attribute=\" \"%&gt;<\/pre>\n<p>where these attributes are key value pairs. Multiple attributes can be there under a directive.<\/p>\n<p><strong>Syntax:\u00a0<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ directive name [attribute=\u201dvalue\u201dattribute=\u201dvalue\u201d\u2026..]%&gt;;<\/pre>\n<h2>Classification of JSP Directives<\/h2>\n<p>Classification of directives in three categories is as follows:<\/p>\n<ol>\n<li>page directive<\/li>\n<li>include directive<\/li>\n<li>taglib directive<\/li>\n<\/ol>\n<p>Let&#8217;s discuss each branch of directives in detail.<\/p>\n<h3>A. Page Directive in JSP<\/h3>\n<p>Page directive contains the instructions that are a means of setting the attributes of the page. They determine interpretation and execution of the page. It applies all the page related attributes to the JSP page and in which it is physically present. It gives instructions to the web container for that JSP page.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ page attribute=\u201dvalue\u201d attribute=\u201dvalue\u201d\u2026%&gt;<\/pre>\n<p>Page directive contains of following attributes:<\/p>\n<ul>\n<li>language=&#8221;scripting language&#8221;<\/li>\n<li>extends=&#8221;className&#8221;<\/li>\n<li>import=&#8221;importList&#8221;<\/li>\n<li>session=&#8221;true|false&#8221;<\/li>\n<li>buffer=&#8221;none|sizekb&#8221;<\/li>\n<li>autoFlush=&#8221;true|false&#8221;<\/li>\n<li>isThreadSafe=&#8221;true|false&#8221;<\/li>\n<li>info=&#8221;info_text&#8221;<\/li>\n<li>contentType=&#8221;ctinfo&#8221;<\/li>\n<li>errorPage=&#8221;error_url&#8221;<\/li>\n<li>isErrorPage=&#8221;true|false&#8221;<\/li>\n<li>pageEncoding= \u201cvalue\u201d<\/li>\n<li>isELignored= \u201ctrue|false\u201d<\/li>\n<\/ul>\n<p>There can be more than one page directive tag in a program. The ordering of the attributes is not important. However, one attribute can only be defined once except the import attribute.<\/p>\n<p>**The page directive attributes won\u2019t show any output as they just set off the start for our JSP code. Thus there won\u2019t be any outputs for page directive.<\/p>\n<p>To understand the functionality of each and every attribute, it\u2019s important to discuss them in detail:<\/p>\n<h4>1. Language attribute in JSP<\/h4>\n<p>JSP architecture allows it to be extended as a framework for server-side scripting. Page directive thus supports language attribute. Java is the default language for this attribute. It is applied to all declarations, expressions, and scriptlets present under the translation including files mentioned in an include directive.<\/p>\n<p>Earlier JSP 1.1 supported none other than java for the language attribute. Although JSP engines individually allow other languages or so.<\/p>\n<p>Newer versions allow the usage of other languages only with some restrictions imposed. The language used as the value for language attribute must support the JRE so that it allows access to the implicit objects, to access get and set methods of JavaBeans, and to use public methods of Java classes. For e.g. JRun 3.0 supports Java as well as JavaScript.<\/p>\n<p><strong>Syntax:\u00a0<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ page language=\u201cvalue\u201d %&gt; \r\n<\/pre>\n<p>When Java is the value of language attribute&#8212;the code gets copied to the auto generated servlet the way it is.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;% int k = 10;\r\n %&gt;\r\nk =\r\n &lt;%= k %&gt;\r\n<\/pre>\n<p>then the generated servlet includes the statements,<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">out.print(\"\\r\\n\");\r\n int k = 10;\r\nout.print(\"\\r\\nk = \");\r\n out.print(k);\r\nout.print(\"\\r\\n\\r\\n\");\r\n<\/pre>\n<p>which treats k as a Java variable,<\/p>\n<p>When the language is javascript&#8212;the code is not as it is. Instead, a servlet engine gets initialized that reads and interprets<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ page language=\"javascript\" %&gt;\r\n &lt;%\r\n var k = 10;\r\n %&gt;\r\n k = &lt;%= k %&gt;\r\n<\/pre>\n<p>A scripting engine specific to JRE will generate following code:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">if (scriptEngine == null)\r\n{\r\ntry { scriptEngine = ScriptEngineFactory.getScriptEngine(\"javascript\"); scriptEngine.init(pageContext);\r\n}\r\n catch (Exception e)\r\n{\r\n      throw new ServletException (\"Error initializing scripting engine.\", e);\r\n }\r\n      if (request.getAttribute(SCRIPT_KEY) != null)\r\n {\r\nscriptEngine.init( pageContext, (String) request.getAttribute(SCRIPT_KEY), (String) request.getAttribute(DECLARATION_KEY));\r\n}\r\nscriptEngine.evaluate(pageContext);\r\n<\/pre>\n<p><strong>For Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ page language = \u201cjava\u201d contentType = \u201ctext\/html\u201d pageEncoding = \u201cISO-8859-1\u201d isErrorPage = \u201cfalse\u201d%&gt;\r\n<\/pre>\n<p><strong>Explanation:<\/strong><br \/>\nIn this example, the page language is Java. Java Compiler will compile all the code under expression tags.<\/p>\n<h4>2. extends in JSP<\/h4>\n<p>The page directive specification allows one to extend the functionalities of a class(parent) to subclass. We need to specify the full name of the class in the extends attribute. Without explicitly coding one can add additional behaviour of another class in a JSP page.<\/p>\n<p>However take some cautions while extending a class because it may affect factors like vendor-specific performance and reliability of a JSP page.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ page extends=\"value\" %&gt;\r\n<\/pre>\n<p><strong>For Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ page language = \u201cjava\u201d contentType = \u201ctext\/html\u201d pageEncoding = \u201cISO-8859-1\u201d %&gt;\r\n&lt;%@ extends = \u201cpack.firstclass\u201d%&gt;\r\n<\/pre>\n<p><strong>Explanation:<\/strong><br \/>\nThe extend tag in this example extends the first class of pack package the class firstclass becomes available to the JSP page.<\/p>\n<h4>3. import in JSP<\/h4>\n<p>The import describes the qualified names of classes that users might use in the JSP page. You can also import a package but import makes that classes. import the classes by their names rather than package names. Imports in JSP is possible for interfaces, enums etc. It is one of the frequently used attributes under page directive. Import statements will convert to import statements of Java.<\/p>\n<p><strong>The syntax is as follows:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ page import=\u201cvalue\u201d %&gt;\r\n&lt;%@ page import=\"java.io.*,java.sql.*,java.util.*\" %&gt;\r\n<\/pre>\n<p>or<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ page import=\"java.io.*\" %&gt;\r\n&lt;%@ page import=\"java.sql.*\" %&gt;\r\n&lt;%@ page import=\"java.util.*\" %&gt;\r\n<\/pre>\n<p>In the auto generated servlet it will convert to following &#8211;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import java.io.*;\r\nimport java.sql.*;\r\nimport java.util.*;\r\n<\/pre>\n<p>Apart from the import statement, four packages get directly imported. We don\u2019t need to mention them. The list of default import is:<br \/>\na. java.lang<br \/>\nb. javax.servlet<br \/>\nc. javax.servlet.http<br \/>\nd. javax.servlet.jsp<\/p>\n<p><strong>For Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ page language=\u201cjava\u201d contentType=\u201ctext\/html\u201d pageEncoding= \u201cISO-8859-1\u201d isErrorPage = \u201cfalse\u201d import=\u201cjava.util.Calender.Date\u201d %&gt;\r\n<\/pre>\n<p><strong>Explanation:<\/strong><br \/>\nThe code in the above example imports the instance of Date from the util package.<\/p>\n<h4>4. session in JSP<\/h4>\n<p>The work of session directive is to see if the HTTP sessions are the requirement of your page or not. It can have two values:<\/p>\n<p><strong>a. If the value of session=&#8221;true&#8221;<\/strong><br \/>\nThis value specifies that the page needs an HTTP session.<br \/>\nBy default the value of this attribute is taken true.<\/p>\n<p><strong>b. If the value of session=&#8221;false&#8221;<\/strong><br \/>\nThis value shows that no HTTP session is required. If this is specified, the implicit variable of the session generation can\u2019t be used if the value of session is false. It causes errors at the time of translation.<br \/>\nIt is suggested that if the page doesn\u2019t need a http session then it should be specified to save the memory and CPU cycles.<\/p>\n<p><strong>Syntax:\u00a0<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ page session= \u201ctrue\/false\u201d %&gt;\r\n<\/pre>\n<p><strong>For Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ page language=\u201cjava\u201d contentType = \u201ctext\/html; charset=ISO-8859-1\u201d pageEncoding = \u201cISO-8859-1\u201d session= \u201cfalse\u201d%&gt;\r\n<\/pre>\n<p><strong>Explanation:<\/strong><br \/>\nThe above code suggests that we don\u2019t want to create a session for the particular JSP page.<\/p>\n<h4>5. The buffer and autoFlush in JSP<\/h4>\n<p>These attributes describe the way the output will be processed. If buffer is set as none, the output gets written to the response directly whereas the output is written to buffer of the specified size. 8kb is the default size of the buffer.<br \/>\nOn the other hand autoFlush can have two values. If it is \u201ctrue\u201d it flushes the output in the buffer if it is full whereas if the value of autoflush is \u201cfalse\u201d that means it will not work and as soon as the buffer will be filled an exception of buffer overflow occurs.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ page buffer=\u201cvalue\u201d %&gt;\r\n&lt;%@ autoFlush=\u201ctrue\/false\u201d %&gt;\r\n<\/pre>\n<p>The following can be the combinations:<\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Buffer<\/b><\/td>\n<td><b>autoFlush<\/b><\/td>\n<td><b>Effect<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">None<\/span><\/td>\n<td><span style=\"font-weight: 400\">True<\/span><\/td>\n<td><span style=\"font-weight: 400\">Characters are written to the servlet response output stream as soon as they are generated.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">None<\/span><\/td>\n<td><span style=\"font-weight: 400\">False<\/span><\/td>\n<td><span style=\"font-weight: 400\">This operation is deemed illegal as, if there is no buffer nothing will be stored and hence autoflush is of no use.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">8<\/span><i><span style=\"font-weight: 400\">kb<\/span><\/i><\/td>\n<td><span style=\"font-weight: 400\">True<\/span><\/td>\n<td><span style=\"font-weight: 400\">An 8kb of default buffer is initialized. It is flushed automatically if it gets filled.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">8kb<\/span><\/td>\n<td><span style=\"font-weight: 400\">False<\/span><\/td>\n<td><span style=\"font-weight: 400\">Again an 8kb size of default buffer is used. As the autoFlush is false, if the buffer an exception occurs.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">size kb<\/span><\/td>\n<td><span style=\"font-weight: 400\">True<\/span><\/td>\n<td><span style=\"font-weight: 400\">Only the buffer size changes in this. Users can choose any integer. A size times 1,024-byte buffer is used. As autoflush is true, when this buffer is filled, it gets flushed automatically.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">size kb<\/span><\/td>\n<td><span style=\"font-weight: 400\">False<\/span><\/td>\n<td><span style=\"font-weight: 400\">It is similar to the 4th combination. The only difference is this the size of buffer varies according to the user i.e. A size times 1,024-byte buffer is used. When the buffer fills, an exception occurs.<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>For Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ page language=\u201cjava\u201d contentType = \u201ctext\/html; charset=ISO-8859-1\u201d pageEncoding = \u201cISO-8859-1\u201d buffer=\u201c8kb\u201d autoFlush=\u201ctrue\u201d%&gt;\r\n<\/pre>\n<p><strong>Explanation:<\/strong><br \/>\nFor the above example, an 8kb buffer will be generated to map the output and it will automatically get flushed when it gets filled.<\/p>\n<h4>6. isThreadSafe in JSP<\/h4>\n<p>A servlet engine, by default, uses a lot of threads and loads a solo instance of generated servlet to service one request. This implies that two or even more threads might be executing the same method of servlet simultaneously. The threads thus can collide. This can lead to interference of threads with each other towards the access of the variable.<\/p>\n<p>Thus, to go a way around with this SingleThreadModel, the isThreadSafe attribute of the page directive helps.<br \/>\nIf you specify isThreadSafe=&#8221;true&#8221;, it implies that you take care of any possible thread conflicts. A defined JSP container safely dispatches multiple requests.<\/p>\n<p>If the value is &#8220;false&#8221;, then SingleThreadModel gets implemented by the JSP container. By default value is taken as \u201ctrue\u201d.<\/p>\n<p><strong>The Syntax for isThreadSafe is as follows:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ page isThreadSafe=\"true\/false\" %&gt;\r\n&lt;%@ page isThreadSafe=\"true\" %&gt;\r\n<\/pre>\n<p>Class signature is generated as follows :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">public class jrun__Chap10__examples__isThreadSafe__ex12ejsp25\r\nextends allaire.jrun.jsp.HttpJSPServlet\r\nimplements allaire.jrun.jsp.JRunJspPage\r\n \r\n&lt;%@ page isThreadSafe=\"false\" %&gt;\r\n<\/pre>\n<p>Class signature is:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">public class jrun__Chap10__examples__isThreadSafe__ex22ejsp25\r\nextends allaire.jrun.jsp.HttpJSPServlet\r\nimplements allaire.jrun.jsp.JRunJspPage, SingleThreadModel \r\n<\/pre>\n<p><strong>For Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ page language=\u201cjava\u201d contentType = \u201ctext\/html; charset=ISO-8859-1\u201d pageEncoding = \u201cISO-8859-1\u201d isThreadsafe= \u201ctrue\u201d%&gt;\r\n\r\n<\/pre>\n<p><strong>Explanation:<\/strong><br \/>\nThis code suggests that multiple threads will be used and they will be synchronized avoiding any thread conflict.<\/p>\n<h4>7. info in JSP<\/h4>\n<p>The info attribute provides the functionality to provide the descriptive info of the JSP page\/servlet. A description is useful for an interactive page.<\/p>\n<p><strong>The Syntax for info is as follows:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ page info=\u201cvalue\u201d %&gt;\r\n&lt;%@ page info=\"Shopping Cart Checkout Page\" %&gt;\r\n<\/pre>\n<p>This value gets compiled to a class. This is made available using the getServletInfo() method.<br \/>\n<strong>For Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ page language=\u201cjava\u201d contentType = \u201ctext\/html; charset=ISO-8859-1\u201d pageEncoding = \u201cISO-8859-1\u201d info= \u201cJSPDirectives_Kajal\u201d%&gt;\r\n<\/pre>\n<p><strong>Explanation:<\/strong><br \/>\nThe value in the info attribute describes that this page is about Directives and thus using getServletInfo() method, servlet retrieves this value.<\/p>\n<h4>8. contentType in JSP<\/h4>\n<p>A JSP page normally generates output in HTML output. But this is not always the case. Using contentType, you can specify the type of content according to you. It can be a jpg image or a pdf.<\/p>\n<p><strong>The Syntax for contentType can be:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ page contentType=\u201cvalue\u201d %&gt;\r\n<\/pre>\n<p>The character set can be specified in addition to the content type. The default value for contentType is &#8220;text\/html; charset=ISO-8859-1&#8221; until and unless the user defines it. For example:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ page contentType=\"type\/subtype; charset=charset\" %&gt;\r\n<\/pre>\n<p><strong>For Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ page language=\u201cjava\u201d contentType = \u201ctext\/html; charset=ISO-8859-1\u201d pageEncoding = \u201cISO-8859-1\u201d session= \u201cfalse\u201d%&gt;\r\n<\/pre>\n<p><strong>Explanation:<\/strong><br \/>\ncontentType sets the type of response as text or html. The character set is specified too for the JSP and response page.<\/p>\n<h4>9. errorPage and isErrorPage in JSP<\/h4>\n<p>While a JSP page is evaluated and an exception occurs, the servlet engine dumps a stack track. This is not desirable for commercial Web applications. JSP offers a simple and convenient solution. We need two attributes: errorPage and isErrorPage and their synchronization.<br \/>\nWhat a JSP can do is to indicate that whenever a page throws an exception, then an error page can be displayed.<\/p>\n<p><strong>Syntax can be:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ page errorPage=\"value\" %&gt;<\/pre>\n<p>Where error_url is the url of the error page of that JSP page in the same servlet context. Now, if the JSP page is Defined with the attribute isErrorPage then it becomes capable of receiving exceptions of the JSP pages that have error pages. That JSP page generated after error needs to have following described in its page directive:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ page isErrorPage=\"true\/false\" %&gt;<\/pre>\n<p>Then It may simply report the exception:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ page isErrorPage=\"true\" session=\"false\"%&gt;\r\n&lt;H3&gt;Application Error&lt;\/H3&gt;\r\n<\/pre>\n<p>The error message is:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;B&gt;&lt;%= exception.getMessage() %&gt;&lt;\/B&gt;<\/pre>\n<p><strong>For Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ page language=\u201cjava\u201d contentType = \u201ctext\/html; charset=ISO-8859-1\u201d pageEncoding = \u201cISO-8859-1\u201d isErrorPage=\u201ctrue\u201d errorPage= \u201cHandleexception.jsp\u201d%&gt;\r\n<\/pre>\n<p><strong>Explanation:<\/strong><br \/>\nIn this code if the page contains error then it should be referred to the Handle Exception page.<\/p>\n<h4>10. pageEncoding in JSP<\/h4>\n<p>It is a character encoding in which JSP files are encoded. The default value for page encoding is ISO-8859-1.<\/p>\n<p>It is a character8-bit (single-byte) coded graphic character set. Page encoding is determined as follows:<\/p>\n<ul>\n<li>Through the value of page encoding in JSP Property group.<\/li>\n<li>Through the value present in page encoding attribute. A translation error is generated if the page encoding of a JSP page is different from its property groups.<\/li>\n<li>Through the contentType attribute that has charset value.<\/li>\n<\/ul>\n<p>The pageEncoding and contentType attribute tells about page encoding of that JSP file in which page directive is physically present.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ pageEncoding= \u201cvalue\u201d %&gt;<\/pre>\n<p><strong>For Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ page language=\u201cjava\u201d contentType = \u201ctext\/html; charset=ISO-8859-1\u201d pageEncoding = \u201cISO-8859-1\u201d session= \u201cfalse\u201d%&gt;\r\n\r\n<\/pre>\n<p><strong>Explanation:<\/strong> The pageEncoding has been shown in the above example using the default value i.e. ISO-8859-1.<\/p>\n<h4>11. isELignored in JSP<\/h4>\n<p>The attribute stands for Expression Language ignored.This attribute specifies the inability of an expression to be evaluated. Simply saying that expression will be considered static and will not be evaluated. However the default value of the attribute is false and expressions are evaluated as specified.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ isELignored = \u201ctrue\/false\u201d%&gt;\r\n<\/pre>\n<p><strong>For Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ page language=\u201cjava\u201d contentType = \u201ctext\/html; charset=ISO-8859-1\u201d pageEncoding = \u201cISO-8859-1\u201d isELignored= \u201cfalse\u201d%&gt;\r\n<\/pre>\n<p><strong>Explanation:<\/strong><br \/>\nFor the above example all the expression language statements will be calculated as they were specified.<\/p>\n<h3>B. Include Directive in JSP<\/h3>\n<p>It works similarly to the #include of the C preprocessor directory. Its work is to merge the contents of another file into .jsp source input stream at the translation phase.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ include\u2026\u2026.%&gt;\r\n&lt;%@ include file=\u201dfilename\u201d%&gt;\r\n<\/pre>\n<p>The \u201cfilename\u201d can be the absolute name or the relative path name.<\/p>\n<p><strong>For Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ include file=\u201dheader.html\u201d&gt;\r\n&lt;%@ include file=\u201dsortmethod\u201d&gt;\r\n<\/pre>\n<p>The include directive however contrasts with the &lt;jsp:include&gt; action. &lt;jsp:include&gt; merges the output of another file at request time into the response output stream unlike include directive. Either of them we can use to include texts, headers, footers etc.<\/p>\n<p><strong>For Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">first.jsp\r\n&lt;%@ page language=\u201cjava\u201dcontentType = \u201ctext\/html; charset=ISO-8859-1\u201d %&gt;\r\n&lt;%@ include file=\"second.jsp\" %&gt;\r\n&lt;html&gt;\r\n&lt;head&gt;&lt;title&gt;Include Application &lt;\/title&gt;&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;a&gt;I am the main including second&lt;\/a&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n\r\nsecond.jsp\r\n&lt;%@ page language=\u201cjava\u201dcontentType = \u201ctext\/html; charset=ISO-8859-1\u201d %&gt;\r\n&lt;html&gt;\r\n&lt;head&gt;&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;a&gt;Header file: &lt;\/a&gt;\r\n&lt;% int num=1; num++; out.println(num);\r\n%&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p><strong>Explanation:<\/strong><br \/>\nIn the above example, there are two jsp files first and second. First file is the main file that includes the second file (code line@ of first.jsp). As the second file is included first, it gets compiled and executed first and then the mail file is compiled.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/include2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81391\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/include2.png\" alt=\"jsp include directive\" width=\"508\" height=\"121\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/include2.png 508w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/include2-300x71.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/include2-150x36.png 150w\" sizes=\"auto, (max-width: 508px) 100vw, 508px\" \/><\/a><\/p>\n<h3>C. Taglib Directive in JSP<\/h3>\n<p>With the use of tag library this directive makes the custom tags available in the current page. It is useful in a JSP page using the standard tag libraries of JSP. It takes custom tags and finds their location in the library. Once it gets the location it searches for that tag in the JSP page. Thus the tag is available for that page.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ taglib uri=\u201ctaglib URI\u201d prefix=\u201cvalue\u201d%&gt;\r\n<\/pre>\n<p>The attributes of this directive are:<\/p>\n<ul>\n<li>tagLibrary URI<\/li>\n<li>tagPrefix<\/li>\n<\/ul>\n<p><strong>a. tagLibraryURI<\/strong><br \/>\nThis attribute contains the URL of a Tag Library Descriptor as a value.<\/p>\n<p><strong>b. tagPrefix<\/strong><br \/>\nIt contains unique prefixes for the identification of custom tags.<\/p>\n<p><strong>For Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ page language=\u201cjava\u201dcontentType = \u201ctext\/html; charset=ISO-8859-1\u201d %&gt;\r\n&lt;%@ taglib prefix=\u201cmytag\u201d uri=\u201chttp:\/\/www.jsp.com\u201d%&gt;\r\n&lt;html&gt;\r\n&lt;head&gt;&lt;title&gt;taglib&lt;\/title&gt;\r\n&lt;mytag: Hi I am a custom tag\/&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\nYou are seeing an example of custom tags.\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p><strong>Explanation:<\/strong> This is an example of custom tags where mytag is the custom tag prefix and it identifies the concerned tag in the head of the code.<\/p>\n<h2>Conclusion<\/h2>\n<p>Finally, In reference to this article, we came to know about the detailed description and usage of directives. We learnt that directives are nothing but a set of defined attributes that instructs the interpretation and execution of a JSP page.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Welcome to DataFlair\u00a0 JSP Directives Tutorial. This article discusses the directives used in JSP. It tells about the attribute used in detail along with their syntax. So let us start!!! JSP Directives A page&#46;&#46;&#46;<\/p>\n","protected":false},"author":10,"featured_media":81390,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22403],"tags":[23086,23084,23085,23088,23087],"class_list":["post-81366","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jsp","tag-jsp-directive-tags","tag-jsp-directives","tag-page-directive-in-jsp","tag-taglib-directive","tag-taglib-directive-in-jsp"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>JSP Directives - Page, Include and Taglib Directives - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn about JSP Directives - a set of defined attributes that instructs the interpretation and execution of a JSP page. Its types are page, taglib, include.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/jsp-directives\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JSP Directives - Page, Include and Taglib Directives - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn about JSP Directives - a set of defined attributes that instructs the interpretation and execution of a JSP page. Its types are page, taglib, include.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/jsp-directives\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-08-31T03:30:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-08-25T08:17:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Directives.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"15 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JSP Directives - Page, Include and Taglib Directives - DataFlair","description":"Learn about JSP Directives - a set of defined attributes that instructs the interpretation and execution of a JSP page. Its types are page, taglib, include.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/jsp-directives\/","og_locale":"en_US","og_type":"article","og_title":"JSP Directives - Page, Include and Taglib Directives - DataFlair","og_description":"Learn about JSP Directives - a set of defined attributes that instructs the interpretation and execution of a JSP page. Its types are page, taglib, include.","og_url":"https:\/\/data-flair.training\/blogs\/jsp-directives\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2020-08-31T03:30:41+00:00","article_modified_time":"2021-08-25T08:17:32+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Directives.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"15 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/jsp-directives\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/jsp-directives\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/a90b082e16aa38d207212d22b0581f33"},"headline":"JSP Directives &#8211; Page, Include and Taglib Directives","datePublished":"2020-08-31T03:30:41+00:00","dateModified":"2021-08-25T08:17:32+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/jsp-directives\/"},"wordCount":2268,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/jsp-directives\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Directives.jpg","keywords":["jsp directive tags","jsp directives","page directive in jsp","taglib directive","taglib directive in jsp"],"articleSection":["JSP Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/jsp-directives\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/jsp-directives\/","url":"https:\/\/data-flair.training\/blogs\/jsp-directives\/","name":"JSP Directives - Page, Include and Taglib Directives - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/jsp-directives\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/jsp-directives\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Directives.jpg","datePublished":"2020-08-31T03:30:41+00:00","dateModified":"2021-08-25T08:17:32+00:00","description":"Learn about JSP Directives - a set of defined attributes that instructs the interpretation and execution of a JSP page. Its types are page, taglib, include.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/jsp-directives\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/jsp-directives\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/jsp-directives\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Directives.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Directives.jpg","width":1200,"height":628,"caption":"JSP Directives"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/jsp-directives\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"JSP Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/jsp\/"},{"@type":"ListItem","position":3,"name":"JSP Directives &#8211; Page, Include and Taglib Directives"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/a90b082e16aa38d207212d22b0581f33","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/dd6de0d647a0185cd6faf264e4ba860b0d85d08d7070766f9cd41bea5bb0b227?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/dd6de0d647a0185cd6faf264e4ba860b0d85d08d7070766f9cd41bea5bb0b227?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/dd6de0d647a0185cd6faf264e4ba860b0d85d08d7070766f9cd41bea5bb0b227?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team is passionate about delivering top-notch tutorials and resources on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. With expertise in the tech industry, we simplify complex topics to help learners excel. Stay updated with our latest insights.","url":"https:\/\/data-flair.training\/blogs\/author\/dfadteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/81366","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=81366"}],"version-history":[{"count":2,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/81366\/revisions"}],"predecessor-version":[{"id":81393,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/81366\/revisions\/81393"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/81390"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=81366"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=81366"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=81366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}