Вы находитесь на странице: 1из 3

Directives

3 types
1. Page
2. Include
3. Taglib

Page
<%@ page %>
The page directive is always at the top of JSP pages. For examples:
<%@ page import="java.util.Date" %>
<%@ page errorPage="errorPage.jsp" %>
<%@ page session="true" %>

Or you can put them together:
<%@ page language="java"
extends="package.class"
import="java.util.Date"
session="true"
buffer="8kb"
autoFlush="true"
isThreadSafe="true"
info="Sample info about this page..."
errorPage="errorPage.jsp"
contentType="text/html; charset=iso-8859-1"
isErrorPage="false"

%>


1. Language=java
Default one is java
2. Import=java.io.*
The default import list is java.lang.*, javax.servlet.*, javax.servlet.jsp.* and
javax.servlet.http.*. This value is currently only defined when the value of the language
directive is java.
3. Extends=
For inhertitance
The value is a Java class name, that names the superclass of the class to which this JSP
page is transformed.
4. Autoflush
Uses boolean value true/false
By default it is true
Used to flush the data in PrintWriter object
Note: it is illegal to set autoFlush to false when buffer=none.
5. Buffersize
The default buffer size is 8kb
6. Contenttype
The default value is: contentType="text/html; charset=iso-8859-1"<%@ page
7. isELIgnored
isELIgnored option provide the ability for you to disable the evaluation of the expression
language (EL).
<html>
<head>
<title>Expression Language</title>
</head>
<body>
<jsp:useBean id="msg"
class="com.jsptutorial.Message" />
<jsp:setProperty name="msg"
property="text"
value="this is an message" />
<span>${msg.text}</span>


</body>
</html>

8. isThreadSafe
by default it is true
we can make it by setting false
jsp handles all the request simultaneously
9. Session
you are telling JSP compiler that you want to use session or not.
The default value of the session attribute is true,
10. ErrorPage
handling exception in jsp
errorPage option allows you to indicate the error page to be displayed when the
error occurs in the current executing page. For example:
<%@ page errorPage="error.jsp" %>

11. isErrorPage
isErrorPage option indicates that the current JSP page can be used as an error page for
other JSP page. When you set isErrorPage equal true, JSP engine creates an implicit
exception object which contains the Throwable object that caused the error page to be
called.
12. Info
Info option allows you to define the description of the servlet. Later on you can
access this value by calling the method:
info="Sample info about this page..."

Servlet.getServletInfo().



Include Directive

<%@ include file="relative url" %>
The filename you specify in the include directive is a relative URL. If you provide a file
name without associated path, the JSP compiler always assumes that the file is in the same
directory as the JSP page.
<%@ include file="includePage.html" %>


taglib Directive
JSP has a set of standard tags for you to use. The syntax of using taglib directive is as follows:
<%@ taglib uri="http://localhost/jsptutorial/taglib/mytaglib"
prefix="jsptutorial" %>

Вам также может понравиться