Page Directive

Definition: 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. The page Directive Specifies the overall properties of Jsp page to the Jsp engine.

Syntax:

<%@ page  [AttributeName = value ] %>

1.     Import: 

Introduction: We can use import attribute for importing classes & interfaces present in a package.  This is similar to Core java import statement.

Case 1:

1.    Without import attribute
     <h1>The Server time is: <%= new java.util.Date( )%></h1> 
    
     2.     With import attributes
  <%@ page import = "java.util.*" %>
 <h1>The Server time is: <%= new Date( ) %></h1>

Output:
Case 2 :
To import multiple packages the following are various possibilities.
     <%@ page import = "java.util.*" %>
     <%@ page import = "java.io.*" %>
     <%@ page import = "java.util.*" import = "java.io.*" %>
     <%@  page import = "java.util.*, java.io.*"  %>

Case 3 :
Within the same Jsp we are not allowed to take any attribute except import multiple times with     different values.  But we can take multiple times with same value.
1.  <%@ page session="true" session = 'true' %>
     // one  attribute with same value
2:  <%@ page session="true" session = 'false' %>
// same attribute with different value.
Output
In Invalid   case we will get Translation time error saying page directive: illegal to have multiple occurrences of session with different values. 

Case 4: 

Inside Jsp it is not required to import the following packages because these are available by default in every Jsp.

1.      javax. Servlet
2.      javax. servlet.http
3.      javax. servlet.jsp
4.       java.lang.*

Note: Static import Concept is not applicable to the Jsp.

<%@ page isError Page =”true”  %>

2. Session
Syntax:

<%@ page session = “true”   %>

Note: The default value of the session attribute is true.

Description:

1.      The session attribute indicates whether or not the JSP page uses HTTP sessions.
2.       In every Jsp session implicit object is by default available.
3.       A value of true means that the JSP page has access to a built-in session object
4.       A value of false means that the JSP page cannot access the built-in session object.
5.      If we don’t want, we can make it unavailable by declaring page directives as follows.
      <%@ page session = “false” %>
If we are not declaring session attribute explicitly   then the jsp engine explicitly place below code in _jspService() method in the jsp engine generated servlet class

HttpSession session = null;
session = pageContext.getSession ( )

If we are declaring session attribute with false value then the above lines won’t be generated.
Session attribute values are not case sensitive. The allowed values for the session attribute are
               TRUE
              True
              FALSE
              False
     <%@  page session = “myjavahub”  %>
Translation time error :  Invalid value for session attribute.
3. Content Type
Definition  :   W e can use this attribute to specify content type and character set  of the response
Syntax     :    <%@ page contentType="text/html; charset=ISO-8859-1" %>
Description :  The default value of the content type attribute is  “text/html” and Charest is ISO-8859-1
Possible values for content Type
    1.  application/msword  -  msword
    2.  text/HTML               HTML file
    3.  text/xml                    XML file
    4.  text/plain                  text file
  4. isELIgnored
1.    In jsp 1.2 version expression languages has introduced.The main objective of Expression Language is to eliminate java, Code from the Jsp.
2.     The isELIgnored attribute takes boolean value of true or false as input.
3.     If isELIgnored is true, then any Expression Language in JSP is ignored.
4.     The default value of isELIgnored is false.
Note : In Jsp 1.2 version the default value of  isELIgnored is  true, but Jsp 2.0    version on wards the default value us false.
Syntax:       <%@page isELIgnored="true"%>
According to jsp 1.2 version :
Case 1: isELIgnored = “true”
Expression language is disabled in the Jsp and any Expression Language Syntax treated as Template text .
test.jsp
    <%@page isELIgnored="false"%>
     Additon : ${2+3}

Output:

Case 2 : isELIgnored = “false”

test.jsp:
      <%@page isELIgnored="false"%>
      Additon : ${2+3}

Output:

                                                                                                NEXT PAGE :>>
Thanks For Making This Possible! Kindly Bookmark and Share it.

Technorati Digg This Stumble Stumble Facebook Twitter

No comments:

Post a Comment