Chinaunix首页 | 论坛 | 博客
  • 博客访问: 524985
  • 博文数量: 151
  • 博客积分: 7010
  • 博客等级: 少将
  • 技术积分: 1405
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-22 14:32
文章分类

全部博文(151)

文章存档

2011年(1)

2010年(23)

2009年(1)

2008年(126)

我的朋友

分类: 系统运维

2008-07-30 11:00:17

Directive elements are used to specify information about the page itself.the classic general directive syntax is:
<%@ directiveName attr1="value1" attr2="value2" %>

一、Page directive
This directive can only be used in JSP pages,not in tag files.It difines page-dependent attributes,such as scripting language,error page,and buffering requirements.

Syntax
<%@ page [autoFlush="true |false"] [buffer="8kb |NN kb|none"]
  [contentType="mimeType "] [errorPage="pageOrContextRelativePath "]
  [extends="className "] [import="packageList "] [info="info "]
  [isELIgnored="true|false ] [isErrorPage="true|false "]
  [isThreadSafe="true |false"] [language="java|language "]
  [pageEncoding="encoding "] [session="true |false"]
%>

Attributes

Attribute name

Default

Description

autoFlush true Set to true if the page buffer should be flushed automatically when it's full, or to false if an exception should be thrown when it's full.
buffer 8kb Specifies the buffer size for the page. The value must be expressed as the size in kilobytes followed by kb, or be the keyword none to disable buffering.
contentType text/html or text/xml The MIME type for the response generated by the page and optionally the response charset, e.g., text/html;charset=Shift_JIS. The charset applies to the JSP page file as well, if pageEncoding isn't specified.

The default MIME type is text/html for a regular JSP page and text/xml for a JSP Document.

If no charset is specified, ISO-8859-1 is used for a regular JSP page and UTF-8 for a JSP Document.

errorPage No default A page- or context-relative URI path for the JSP page, servlet, or static page to forward to in case an exception is thrown by code in the page.
extends No default The fully qualified name of a Java class that the generated JSP page implementation class shall extend. The class must implement the JspPage or HttpJspPage interface in the javax.servlet.jsp.package.

Note that the recommendation is to not use this attribute. Specifying your own superclass restricts the JSP container's ability to provide a specialized, high-performance superclass.

import No default A Java import declaration, i.e., a comma-separated list of fully qualified class names or package names followed by .* (for all public classes in the package).
info No default Text that a web container may use as a description of the page in its administration user interface.
isELIgnored false Set to true to treat ${...} character sequences as template text instead of EL expressions, false otherwise.
isErrorPage false Set to true for a page that is used as an error page, to make the implicit exception variable available to scripting elements. Use false for regular JSP pages.
isThreadSafe true Set to true if the container is allowed to run multiple threads through the page (i.e., let the page serve parallel requests). If set to false, the container serializes all requests for the page. It may also use a pool of page implementation class instances to serve more than one request at a time. The recommendation is to always use true and handle multithread issues by avoiding JSP declarations, and to ensure that all objects used by the page are thread-safe.
language java Defines the scripting language used in the page.
pageEncoding See Description The encoding used for the JSP page file, as well as the response charset if no charset is specified by contentType.

If this attribute is omitted, but a charset is specified for contentType, that charset is also used of the page; if contentType doesn't specify a charset, ISO-8859-1 is used for a regular JSP page, and UTF-8 is used for a JSP Document.

session true Set to true if the page should participate in a user session. If set to false, neither the session scope nor the implicit session variable is available to JSP elements in the page.

二、Include Directive
Include a static file,merging its content with the including page before the combined result is converted to a JSP page implementation class.

Syntax
<%@ include file="pageOrContextRelativePath" %>
Attributes

Attribute name

Default

Description

file No default A page-relative or context-relative URI path for the file to include.

三、Taglib Directive
declares a tag library,containing custom actions,that is used in the page.

Syntax
<%@ taglib prefix="prefix" [uri="taglibURI" | tagdir="contextRelativePath"]%>
Attributes

Attribute name

Default

Description

prefix No default The prefix to use in the action element names for all actions in the library.
uri No default Either a symbolic name for the tag library that is defined in the TLD for the library or in the web.xml file for the application, or a page-relative or context-relative URI path for the library's TLD file or JAR file.
tagdir No default The context-relative path to a directory containing tag files, starting with /WEB-INF/tags.

Example
<%@ taglib prefix="ora" uri="orataglib" %>
<%@ taglib prefix="c" uri="" %>
<%@ taglib prefix="mylib" tagdir="/WEB-INF/tags/mylib" %>

四、Tag Directive
This directive can only be used in Tag files.It defines properties of the file itself,such as encoding and how to treat EL expressions.

Syntax
<%@ tag [body-content="empty|scriptless |tagdependent"]
  [description="description "] [display-name="displayName "]
  [dynamic-attributes="attrCollVar "] [example="example "]
  [import="packageList "] [isELIgnored="true|false "] [language="java |language "]
  [large-icon="largeIconPath "] [pageEncoding="encoding "]
  [small-icon="smallIconPath "]
%>

Attributes

Attribute name

Default

Description

body-content scriptless The custom action body content type, one of empty, scriptless, or tagdependent.
description No default A description of the custom action that can be displayed by a page-authoring tool.
display-name No default A descriptive name for the custom action that can be displayed by a page-authoring tool.
dynamic-attributes No default The name of a variable to hold undeclared attributes. The variable is made available in the tag file's page scope as a java.util.Map with the attribute names as keys and the attribute values as the values.
example No default An example of how to use the custom action that can be displayed by a page-authoring tool.
import No default A Java import declaration, i.e., a comma-separated list of fully qualified class names or package names followed by .* (for all public classes in the package).
isElIgnored false Set to true to treat ${...} character sequences as template text instead of EL expressions, false otherwise.
language java Defines the scripting language used in the page.
large-icon No default A context- or file-relative path to a 32x32 pixel GIF or JPEG image file that can be displayed by a page-authoring tool.
pageEncoding ISO-8859-1 The encoding used for the tag file.
small-icon No default A context- or file-relative path to a 16x16 pixel GIF or JPEG image file that can be displayed by a page-authoring tool.

五、Variable Directive
This directive can only be used in tag files.It declares variables explosed by the tag file to the page where the corresponding custom action is used.

Syntax
<%@ variable name-given="attrAndVarName " |
  name-from-attribute="attrName " alias="varName "
  [declare="true |false"] [description="description "] [scope="AT_BEGIN|AT_END|NESTED "] [variable-class="varType "]
%>

Attributes

Attribute Name

Default

Description

alias No default The name of the local page scope variable the tag file uses to hold the value it creates. The container copies the value of the local variable to the variable in the invoking page's page scope named by the attribute specified by the name-from-attribute attribute.
declare true Set to false if no scripting variable declaration should be created in the page implementation class.
description No default A description of the variable that can be displayed by a page-authoring tool.
name-from-attribute No default The name of the attribute that specifies the variable to hold the value created by the tag file. This attribute must be used in combination with the alias attribute, and must not be used with the name-given attribute.
name-given No default The name of the variable in the invoking page's page scope the tag file uses to expose the value it creates. This attribute must not be used with the name-from-attribute attribute.
scope NESTED The visibility of the variable, one of AT_BEGIN, AT_END, or NESTED.
variable-class String The variable type; a fully qualified class or interface name.
Example
<%@ variable name-from-attribute="var" alias="current"
  variable-class="java.util.Date" scope="AT_END" %>
<%@ attribute name="var" required="true" rtexprvalue="false" %>

六、Attribute Directive
This directive can only be used in tag files.It declares the attributes the tag file supports.

Syntax
<%@ attribute name="attrName "
  [description="description "] [required="true|false "]
  [fragment="true|false " | [type="attrDataType "] [rtexprvalue="true |false"]]
%>

Attibutes

Attribute name

Default

Description

description No default A description of the attribute that can be presented to a page author by an authoring tool.
fragment false Set to true if the attribute represents a fragment, set by a element. If false, the attribute is converted to the type specified by the type attribute.
name No default The attribute name.
required false Set to true if the page author must provide an attribute value.
rtexprvalue true Set to false if the attribute value must be provided as a static text value. If true, the attribute can be set by an EL or Java expression or a element, evaluated at runtime.
type String The attribute data type. Primitive types are not supported, only Java classes and interfaces.
Example
<%@ attribute name="date" type="java.util.Date" %>
<%@ attribute name="pattern" fragment="true" %>

 




阅读(961) | 评论(0) | 转发(0) |
0

上一篇:JSP页面元素

下一篇:Scripting Elements

给主人留下些什么吧!~~