JSP Tutorials

JSP Directives
Previous Home Next
adplus-dvertising

JSP directives

In jsp directives are used to tells the web container which is translate a JSP page in servlet.

Three types Directives:

  1. page directive
  2. include directive
  3. taglib directive

Syntax used

<%@ directive attribute="value" %>  

JSP page directive

In page directive is defines of the attributes which apply in an entire JSP page.

Syntax used

<%@ page attribute="value" %>  

Attributes used

  1. import
  2. contentType
  3. extends
  4. info
  5. buffer
  6. language
  7. isELIgnored
  8. isThreadSafe
  9. autoFlush
  10. session
  11. pageEncoding
  12. errorPage
  13. isErrorPage
  1. import
  2. It is used to import class which is connect of all package with similar to import keyword in java class or interface.

    Example

    	<html>  
        <body>
        <%@ 
    
    page import="java.util.Date" %>  
        Today is: <%= new Date( ) %>   
        </body>  
        </html>  
    
  3. contentType
  4. In contentType attribute is used the MIME(Multipurpose Internet Mail Extension) which is HTTP response and performed "text/html;charset=ISO-8859-1".

    Example

    	<html>  
        <body>  
        <%@ 
    
    page contentType=application/msword 
    
    %>  
        Today is: <%= new java.util.Date() %>  
        </body>  
        </html>
    
  5. extends
  6. It is performed the parent class for inherited by servlet.

  7. info
  8. It is sets the information of the JSP page when it is inherite by perform with getServletInfo() method of Servlet interface.

    Example

        <html>  
        <body>    
        <%@ 
    
    page info="composed by Sonoo Jaiswal" %>  
        Today is: <%= new java.util.Date() %>  
        </body>  
        </html>  
    

    In web container can be create method getServletInfo() for resulting servlet.

    Example

     public String 
    
    getServletInfo() {  
          return "composed by Sonoo 
    
    Jaiswal";   
        }  
    
    
  9. buffer
  10. It makes sets the buffer size(kilobytes) which is handle output by the JSP page and default buffer size is 8Kb.

    Example

    	<html>  
        <body> 
        <%@ 
    
    page buffer="16kb" %>  
        Today is: <%= new java.util.Date() %>  
        </body>  
        </html>  
    
  11. language
  12. It is specified of the scripting language.

  13. isELIgnored
  14. In this attribute to be ignore the Expression Language (EL) in jsp by the isELIgnored attribute. By default its value is false i.e. Expression Language is enabled by default. We see Expression Language later.

    <%@ page isELIgnored="true" %>//Now EL 
    
    will be ignored  
    
    isThreadSafe

    In this attribute is performed Servlet and JSP both are multithreaded and you want to control this behaviour of JSP page, you can use isThreadSafe attribute of page directive.

    In isThreadSafe value is true then you make it false, the web container will serialize the multiple requests.

    <%@ page isThreadSafe="false" %>
    

    The web container in such a case, will generate the servlet as:

     public class SimplePage_jsp extends HttpJspBase   
          implements SingleThreadModel{  
        .......  
        }  
    
  15. errorPage
  16. The errorPage attribute is used to define the error page, if exception occurs in the current page, it will be redirected to the error page.

    Example of errorPage attribute

        //index.jsp  
        <html>  
        <body>   
        <%@ 
    
    page errorPage="myerrorpage.jsp" %>  
         <%= 
    
    100/0 
    
    %>  
        </body>  
        </html>  
    
  17. isErrorPage
  18. The isErrorPage attribute is used to declare that the current page is the error page. Note: The exception object can only be used in the error page.

    Example of isErrorPage attribute

    	//myerrorpage.jsp  
        <html>  
        <body>  
        <%@ 
    
    page isErrorPage="true" %>  
         Sorry an exception occured!<br/>  
        The exception is: <%= exception %>   
    
    
        </body>  
        </html>  
    
Previous Home Next