

{"id":81349,"date":"2020-08-02T09:00:12","date_gmt":"2020-08-02T03:30:12","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=81349"},"modified":"2021-08-25T13:48:25","modified_gmt":"2021-08-25T08:18:25","slug":"jsp-page-directives","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/jsp-page-directives\/","title":{"rendered":"JSP Page Directive &#8211; JSP Directives Type"},"content":{"rendered":"<p>Welcome to DataFlair JSP Tutorial series. This article deals with the most important directive that is JSP page directive and its attributes in detail. It discusses include and taglib directive too. So let&#8217;s start!!!<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Page-Directive.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81444\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Page-Directive.jpg\" alt=\"JSP Page Directive\" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Page-Directive.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Page-Directive-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Page-Directive-1024x536.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Page-Directive-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Page-Directive-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Page-Directive-520x272.jpg 520w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><\/p>\n<h2>JSP Page Directive<\/h2>\n<p>The page directive is an important part of directives. Page directive has instructions that set the attributes of that JSP page. They determine the interpretation and execution of that JSP page.<br \/>\n<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>It gives instructions for that JSP page in which it is physically present to the JSP web container.<\/p>\n<p><strong>Page directive has following attributes:<\/strong><\/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>More than one page directive tag can be in a program as well as the order 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<h3>1. JSP language<\/h3>\n<p>JSP architecture allows it to be extended as a framework for server-side scripting only. For this reason, page directive supports language attribute.<\/p>\n<p>By default, the value for this attribute is Java. It applies to all declarations, expressions, and scriptlets present under the files mentioned in an include directive.<\/p>\n<p>Newer versions allow the other languages only with some restrictions. 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.<br \/>\n<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; %&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\nint k = 10;\r\nout.print(\"\\r\\nk = \");\r\nout.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;% var k = 10; %&gt;\r\n k = &lt;%= k %&gt;\r\n<\/pre>\n<p><strong>A scripting engine specific to JRE will generate following code:<\/strong><\/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><\/p>\n<p>The language here is Java. Java Compiler will compile all the code under expression tags.<\/p>\n<h3>2. JSP extends<\/h3>\n<p>The page directive allows extending the functionalities of a class (parent) to subclass. Specify the full name of the class under the extends attribute that you want to extend. Without explicitly coding one can add an additional behavior 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><\/p>\n<p>The extend tag in this example extends the first class of pack package that makes the first class available to this JSP page.<\/p>\n<h3>3. JSP import<\/h3>\n<p>The import describes the qualified names of classes, the JSP page will use. You can also import a package, but import makes that class. Import the classes by their names rather than package names. Imports can be done for interfaces, enumerations, etc. It is one of the frequently used attributes under the page directive.<\/p>\n<p>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 converts 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:<\/p>\n<p>a. 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<h3>4. JSP session<\/h3>\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>a. If the value of session=&#8221;true&#8221;<br \/>\nThis value specifies that the page needs an HTTP session. The default value of this attribute is true.<\/p>\n<p>b. If the value of session=&#8221;false&#8221;<br \/>\nThis value shows that the page doesn\u2019t require an HTTP session. The implicit variable of the session generation can\u2019t be used if the value of the session is false. It causes errors at the time of translation.<br \/>\nIf the page doesn\u2019t need a http session then Specify it to save the memory and CPU cycles.<\/p>\n<p><strong>Syntax:<\/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 \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<h3>5. JSP buffer and autoFlush<\/h3>\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><strong>The following are the possible combinations:<\/strong><\/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><b>None<\/b><\/td>\n<td><span style=\"font-weight: 400\">True<\/span><\/td>\n<td><span style=\"font-weight: 400\">The result is directly written to the output stream of the auto generated servlet.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>None<\/b><\/td>\n<td><span style=\"font-weight: 400\">False<\/span><\/td>\n<td><span style=\"font-weight: 400\">This operation is 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><b>8<\/b><b><i>kb<\/i><\/b><\/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 once it fills.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>8kb<\/b><\/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 fills an exception occurs.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>size kb<\/b><\/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 fills, it gets flushed automatically.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>size kb<\/b><\/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 once it fills.<\/p>\n<h3>6. JSP isThreadSafe<\/h3>\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;, the JSP container implements SingleThreadModel. By default value is taken as \u201ctrue\u201d. The Syntax for isThreadSafe is as follows:<\/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<h3>7. JSP info<\/h3>\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.The Syntax for info is as follows:<\/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.<\/p>\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 info= \u201cJSPDirectives_Kajal\u201d%&gt;<\/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<h3>8. contentType<\/h3>\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. The Syntax for contentType can be:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ page contentType=\u201cvalue\u201d %&gt;<\/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;<\/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<h3>9. JSP errorPage and isErrorPage<\/h3>\n<p>While a JSP page is being 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. The <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.<br \/>\nNow, if the JSP page contains 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;\r\n<\/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\nThe error message is:\r\n&lt;B&gt;&lt;%= exception.getMessage() %&gt;&lt;\/B&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 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<h3>10. JSP pageEncoding<\/h3>\n<p>It is a character encoding in which JSP files are encoded. The default value for page encoding is ISO-8859-1. It is a character 8-bit (single-byte) coded graphic character set. Page encoding<\/p>\n<p>1. Through the value of page encoding in JSP Property group.<br \/>\n2. 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.<br \/>\n3. Through the contentType attribute that has charset value.<\/p>\n<p>The pageEncoding and contentType attribute tells about page encoding of the That JSP file in which page directive is physically present.<br \/>\n<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;<\/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<h3>11. JSP isELignored<\/h3>\n<p>The attribute stands for Expression Language ignored. This attribute specifies the inability of an expression to be evaluated saying that expression is static and will not be evaluated. However, the default value of the attribute is false and expressions are evaluated as specified.<br \/>\n<strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ isELignored = \u201ctrue\/false\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 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. They will not be ignored.<\/p>\n<h2>JSP Include Directive<\/h2>\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\nThe \u201cfilename\u201d can be the absolute name or the relative path name as following:\r\n            &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 can be used to include texts, headers, footers, etc.<\/p>\n<p><strong>For Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">include1.jsp\r\n&lt;%@ page language=\"java\" contentType = \"text\/html; charset=ISO-8859-1\" %&gt;\r\n&lt;%@ include file=\"include2.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\ninclude2.jsp\r\n&lt;%@ page language=\"java\" contentType = \"text\/html; charset=ISO-8859-1\" %&gt;\r\n&lt;html&gt;\r\n&lt;head&gt;&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;a&gt;Second file will be executed first &lt;\/a&gt;\r\n&lt;% int num=1; num++; %&gt;\r\n&lt;br\/&gt;\r\n&lt;% out.println(\"The result is:\" + num);%&gt;\r\n&lt;br\/&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 include1 and include2. First file is the main file that includes the second file. As the second file is first, it compiles and executes first and then the main file is compiled.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image1-7.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81545\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image1-7.png\" alt=\"jsp page directive\" width=\"1366\" height=\"190\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image1-7.png 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image1-7-300x42.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image1-7-1024x142.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image1-7-150x21.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image1-7-768x107.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image1-7-520x72.png 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<h2>JSP Taglib Directive<\/h2>\n<p>With the use of tag library this directive makes the custom tags available in the current page. The JSP page uses them through the standard tag libraries of JSP.<\/p>\n<p>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 can be shown as:<\/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.getsuccess.com\/jsp_core\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>In this article, we discussed JSP page directive in detail with syntax and examples. Page directive is an important part of a JSP page as they determine the interpretation of a JSP code. They act like an index to the book. Further, we discussed all the attributes of page directive such as language, is thread safe, isErrorPage, etc. that form a crucial part of JSP coding. In addition to it, we also glanced at include and taglib directives that are equally important as page directive.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Welcome to DataFlair JSP Tutorial series. This article deals with the most important directive that is JSP page directive and its attributes in detail. It discusses include and taglib directive too. So let&#8217;s start!!!&#46;&#46;&#46;<\/p>\n","protected":false},"author":10,"featured_media":81444,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22403],"tags":[23084,23101,23102],"class_list":["post-81349","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jsp","tag-jsp-directives","tag-jsp-page-directive","tag-jsp-taglib-directive"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>JSP Page Directive - JSP Directives Type - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn about JSP Page Directives with Syntax and Examples.Page directive is important part of JSP page as they determine the interpretation of a JSP code.\" \/>\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-page-directives\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JSP Page Directive - JSP Directives Type - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn about JSP Page Directives with Syntax and Examples.Page directive is important part of JSP page as they determine the interpretation of a JSP code.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/jsp-page-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-02T03:30:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-08-25T08:18:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Page-Directive.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=\"14 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JSP Page Directive - JSP Directives Type - DataFlair","description":"Learn about JSP Page Directives with Syntax and Examples.Page directive is important part of JSP page as they determine the interpretation of a JSP code.","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-page-directives\/","og_locale":"en_US","og_type":"article","og_title":"JSP Page Directive - JSP Directives Type - DataFlair","og_description":"Learn about JSP Page Directives with Syntax and Examples.Page directive is important part of JSP page as they determine the interpretation of a JSP code.","og_url":"https:\/\/data-flair.training\/blogs\/jsp-page-directives\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2020-08-02T03:30:12+00:00","article_modified_time":"2021-08-25T08:18:25+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Page-Directive.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":"14 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/jsp-page-directives\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/jsp-page-directives\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/a90b082e16aa38d207212d22b0581f33"},"headline":"JSP Page Directive &#8211; JSP Directives Type","datePublished":"2020-08-02T03:30:12+00:00","dateModified":"2021-08-25T08:18:25+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/jsp-page-directives\/"},"wordCount":2065,"commentCount":1,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/jsp-page-directives\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Page-Directive.jpg","keywords":["jsp directives","JSP Page Directive","JSP Taglib Directive"],"articleSection":["JSP Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/jsp-page-directives\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/jsp-page-directives\/","url":"https:\/\/data-flair.training\/blogs\/jsp-page-directives\/","name":"JSP Page Directive - JSP Directives Type - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/jsp-page-directives\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/jsp-page-directives\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Page-Directive.jpg","datePublished":"2020-08-02T03:30:12+00:00","dateModified":"2021-08-25T08:18:25+00:00","description":"Learn about JSP Page Directives with Syntax and Examples.Page directive is important part of JSP page as they determine the interpretation of a JSP code.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/jsp-page-directives\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/jsp-page-directives\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/jsp-page-directives\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Page-Directive.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Page-Directive.jpg","width":1200,"height":628,"caption":"JSP Page Directive"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/jsp-page-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 Page Directive &#8211; JSP Directives Type"}]},{"@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\/81349","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=81349"}],"version-history":[{"count":5,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/81349\/revisions"}],"predecessor-version":[{"id":81548,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/81349\/revisions\/81548"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/81444"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=81349"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=81349"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=81349"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}