1- page directives


1- autoFlush – <%@ page autoFlush=”false” %>

Its default value is true and output is flushed automatically when buffer is full. If we set it to false, the buffer will not be flushed automatically and if it’s full, we will get exception for buffer overflow.

2-buffer – <%@ page buffer=”16kb” %>

we can use this attribute to set the buffer size in KB to handle output generated by JSP page. Default value of buffer attribute is 8kb.

3- contentType – <%@ page contentType=”text/html; charset=US-ASCII” %>

This attribute is used to set the content type and character set of the response. The default value of contentType attribute is”text/html; charset=ISO-8859-1″.

4- deferredSyntaxAllowedAsLiteral-

<%@ page deferredSyntaxAllowedAsLiteral=”false” %>

This attribute allows any syntax to be visible as String only.

5- errorPage – <%@ page errorPage=”errorHandler.jsp” %>

If the JSP throws exception, the request is redirected to the error handler defined in this attribute.

6- extends- <%@ page extends=”org.apache.jasper.runtime.HttpJspBase” %>

This is very rarely used and we can use it if we have extended HttpServlet and overridden some of it’s implementations.

7- import- <%@ page import=”java.util.Date,java.util.List,*” %>

This is similar to import statements in java classes, interfaces.

8- info – <%@ page info=”Home Page JSP” %>

we can retrieve it using Servlet interface getServletInfo() method.

9- isELIgnored – <%@ page isELIgnored=”true” %>

We can ignore the Expression Language (EL) in JSP using this page directive attribute. Its default value is false, so EL is enabled by default.

10- isErrorPage – <%@ page isErrorPage=”true” %>

This attribute is used to declare that current JSP page is an error page. It’s default value is false.

11-isThreadSafe – <%@ page isThreadSafe=”true” %>

If we set it’s value to false, the generated servlet will implement SingleThreadModel and eventually we will loose all the benefits of servlet multi-threading features. You should never set it’s value to false.

12- language – <%@ page language=”java” %>

language attribute is added to specify the scripting language used in JSP page. It’s default value is “java” and this is the only value it can have. May be in future, JSPs provide support to include other scripting languages like C++ or PHP too.

13- pageEncoding – <%@ page pageEncoding=”US-ASCII” %>

We can set response encoding type with this page directive attribute, its default value is “ISO-8859-1”.

14- session – <%@ page session =”false” %>

We can use this attribute to indicate compiler to not create session by default. It’s default value is true and session is created.

15- trimDirectiveWhitespaces  – <%@ page trimDirectiveWhitespaces =”true” %>

. Its default value is false. It helps in reducing the generated code size, notice the generate servlet code keeping this attribute value as true and false. You will notice no out.write("\n") when it’s true.

2- include directives

JSP include directive is used to include the contents of another file to the current JSP page. The included file can be HTML, JSP, text files etc.

<%@ include file=”test.html” %>

3- taglib directives

<%@ taglib uri=”/WEB-INF/c.tld” prefix=”c”%>

JSP taglib directive is used to define a tag library with prefix that we can use in JSP.

note-other prefixes are c,fmt,sql,x,fn