This section illustrates you about the page directive of the JSP page which works for the entire JSP page. These directives apply different properties for the page like language support, page information and import etc. by using the different attributes of the directives. There are three types of directives are as follows:
In this section, you will learn about the page directive and it's attributes and explanation one-by-one. This is the directive of the JSP page which defines the properties for the entire JSP page by using it's different attributes and set values of the attributes as per requirements.
Syntax of the declaration of the page directive with it's attributes is <%@ page attributeName="values" %>. The space between the tag <%@ and %> before the page (directive name) and after values of the last attribute, is optional, you can leave the space or not.
Following are name of the attributes of the page directive used in JSP:
language: This is the attribute of the page directive of the JSP which is used for specifying some other scripting languages to be used in your JSP page but in this time, it's value is almost become java that is optional.
extends: This is the attributes of the page directive of the JSP which is used for specifying some other java classes to be used in your JSP page like packagename.classname. The fully qualified name of the superclass of the Java class will be accepted.
import: This attribute imports the java packages and it's classes more and more. You can import more than one java packages and classes by separating with comma (,). You can set the name of the class with the package name directly like packagename.classname or import all classes of the package by using packagename.*.
session: This attribute sets a boolean value either true or false. If the value of session attribute is true then the session object refers to the current or a new session because the client must be in the HTTP session for running the JSP page on the server. If you set the value of session object false then you can not use the session object or <jsp:useBean> element with scope="session" in JSP page. And then if a type of error occurs i.e. called the translation-time error. The default value of session attribute is true.
buffer: This attribute sets the buffer size in kilobytes i.e. used by the out object to handle output generated by the JSP page on the client web browser. If you specify the buffer size then the output will be buffered with at least 8kb because the default and minimum value of the buffer attribute is 8kb.
autoFlush: This attribute of the page directive supports for flushing buffer automatically when the buffer is full. The value of the autoFlush attribute is either true or false. If you will specify the true value then the buffer will be flushed otherwise it will generate a raised exception if you set the false value. You cannot set the false value if the buffer size is none.
isThreadSafe: This attribute support the facility of maintaining thread for sending multiple and concurrent requests from the JSP container to the JSP page if you specify the true value of the attribute otherwise if you specify the false value of the attribute then the JSP container can send only one request at one time. The default value of the attribute is true.
info: This attribute simply sets the information of the JSP page which is retrieved later by using Servlet.getServletInfo() method. The value of the attribute will be a text string.
errorPage: This attribute sets a url (relative path starting from the "/" which refers from the root directory of your JSP application). If any exception is generated the the attribute refers to the file which is mentioned in the given url. If you do not specify the url then the attribute refers to the current page of your JSP application if any exception generated.
isErrorPage: This attribute sets the boolean value either true or false. You can use the exception object in the JSP page if you set the true value of the attribute otherwise you cannot use the exception object because the default value of the attribute is false.
contentType: This attribute specifies the MIME type and the character encoding i.e. used for the JSP response. The default MIME type is "text/html" and the default character set is "ISO-8859-1". You can also specify other.
pageEncoding: This attribute specifies the language that the page uses when the page is sent to the browser. This attribute works like the meta tag of the HTML markup language.
isELIgnored: This is a boolean attribute that specifies either true or false value. If you set the attribute value is true then any type of the EL expressions will be ignored in the JSP page.
In the following program, <% and %> JSP tags. Java codes are written in between the both tag.
Above is the method of the out object of the Java System class. This method takes a text string to be printed on the browser.
Here is the code of the program:
<[email protected] language="java" %> <html> <head><title>Hello World JSP Page.</title></head> <body> <font size="10"> <% String name="Roseindia.net"; out.println("Hello " + name + "!"); %> </font> </body> </html>
Output of the program:
Posted on: February 6, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles