Page Directive
Defines attributes that apply to an entire JSP page.
JSP Syntax
<%@ page
[ language="java" ]
[ extends="package.class" ]
[ import="{package.class | package.*}, ..." ]
[ session="true|false" ]
[ buffer="none|8kb|sizekb" ]
[ autoFlush="true|false" ]
[ isThreadSafe="true|false" ]
[ info="text" ]
[ errorPage="relativeURL" ]
[ contentType="mimeType [ ; charset=characterSet ]" |
"text/html ; charset=ISO-8859-1" ]
[ isErrorPage="true|false" ]
[ pageEncoding="characterSet | ISO-8859-1" ]
%>
XML Syntax
<jsp:directive.page pageDirectiveAttrList />
where pageDirectiveAttrList is the same as the list in the JSP syntax.
Examples
<%@ page import="java.util.*, java.lang.*" %>
<%@ page buffer="5kb" autoFlush="false" %>
<jsp:directive.page errorPage="error.jsp" />
Description
The page directive applies to an entire JSP page and any of its static include files, which together are called a translation unit. A static include file is a file whose content becomes part of the calling JSP page. The page directive does not apply to any dynamic resources; see <jsp:include> for more information.
You can use the page directive more than once in a translation unit, but you can only use each attribute, except import, once. Because the import attribute is similar to the import statement in the Java programming language, you can use a page directive with import more than once in a JSP page or translation unit.
No matter where you position the page directive in a JSP page or included files, it applies to the entire translation unit. However, it is often good programming style to place it at the top of the JSP page.
Attributes
* language="java"
The scripting language used in scriptlets, declarations, and expressions in the JSP page and any included files. In v1.2, the only allowed value is java.
* extends="package.class"
The fully qualified name of the superclass of the Java class this JSP page will be compiled to. Use this attribute cautiously, as it can limit the JSP container's ability to provide a specialized superclass that improves the quality of the compiled class.
* import="{package.class | package.*}, ..."
A comma-separated list of Java packages that the JSP page should import. The packages (and their classes) are available to scriptlets, expressions, and declarations within the JSP page. If you want to import more than one package, you can specify a comma-separated list after import or you can use import more than once in a JSP page.
The following packages are implicitly imported, so you don't need to specify them with the import attribute:
java.lang.*
javax.servlet.*
javax.servlet.jsp.*
javax.servlet.http.*
You must place the import attribute before the element that calls the imported class.
* session="true|false"
Whether the client must join an HTTP session in order to use the JSP page. If the value is true, the session object refers to the current or new session.
If the value is false, you cannot use the session object or a <jsp:useBean> element with scope=session in the JSP page. Either of these usages would cause a translation-time error.
The default value is true.
* buffer="none|8kb|sizekb"
The buffer size in kilobytes used by the out object to handle output sent from the compiled JSP page to the client web browser. The default value is 8kb. If you specify a buffer size, the output is buffered with at least the size you specified.
* autoFlush="true|false"
Whether the buffered output should be flushed automatically when the buffer is full. If set to true (the default value), the buffer will be flushed. If set to false, an exception will be raised when the buffer overflows. You cannot set autoFlush to false when buffer is set to none.
* isThreadSafe="true|false"
Whether thread safety is implemented in the JSP page. The default value is true, which means that the JSP container can send multiple, concurrent client requests to the JSP page. You must write code in the JSP page to synchronize the multiple client threads. If you use false, the JSP container sends client requests one at a time to the JSP page.
* info="text"
A text string that is incorporated verbatim into the compiled JSP page. You can later retrieve the string with the Servlet.getServletInfo() method.
* errorPage="relativeURL"
A pathname to a JSP page that this JSP page sends exceptions to. If the pathname begins with a /, the path is relative to the JSP application's document root directory and is resolved by the web server. If not, the pathname is relative to the current JSP page.
* isErrorPage="true|false"
Whether the JSP page displays an error page. If set to true, you can use the exception object in the JSP page. If set to false (the default value), you cannot use the exception object in the JSP page.
* contentType="mimeType [; charset=characterSet ]" |
"text/html;charset=ISO-8859-1"
The MIME type and character encoding the JSP page uses for the response. You can use any MIME type or character set that are valid for the JSP container. The default MIME type is text/html, and the default character set is ISO-8859-1.
* pageEncoding="characterSet | ISO-8859-1"
The page source character encoding. The value is a IANA charset name. The default character encoding is ISO-8859-1.
Tip
If you need to include a long list of packages or classes in more than one JSP page, you can create a separate JSP page with a page directive that contains the import list and include that file in the main JSP page.
<jsp:directive.page import="zero.space.ch03.BookBean"/>
那么这中形式和我们经常使用的如下形式
<%@ page import="zero.space.ch03.BookBean" %>
有什么区别呢,也就是我这篇文章要详解讲解的。大家有不懂的地方可以直接登录http://www.hf-accp.com来获得最新的技术讲解。
<jsp:directive.page import="zero.space.ch03.BookBean"/>
等效于
<%@ page import="zero.space.ch03.BookBean" %>
但是有一点不同,如果你把所有类包的引入放在一个JSP中,在其他jsp中通include引入那个jsp。这时引入类就必须采用
<%@ page import="zero.space.ch03.BookBean" %>
这样的写法。
<jsp:directive.page import="zero.space.ch03.BookBean"/>这种写法只能在同一个jsp页面中使用,不能跨页调用
分享到:
相关推荐
8. **页面指令(The page Directive)**:定义页面的基本属性,如标题、编码、错误处理策略等。 9. **根属性指令(The root-attributes Directive)**:用于设置页面根元素的属性,如ID、类名等。 10. **标签库...
1. **网页指令(The page directive)**:用于定义JSP页面的属性,如编程语言、继承的Servlet类、导入的Java包等。例如: ```jsp <%@ page language="Java" extends="HttpServlet" import="java.io.*, java.util....
A directive is a way to give special instructions to the container at page translation time. The page directive is written on the top of the jsp page. Html tags in jsp In this example we have used ...
1. **Page Directive**: - `language`: 指定JSP页面的脚本语言,如`"java"`。 - `extends`: 定义JSP页面继承自哪个Servlet类。 - `import`: 引入Java类库,例如`"java.util.*"`。 - `buffer`: 控制响应缓冲区的...
1. **页面指令**(Page Directive):页面指令用于设置整个JSP页面的属性,例如定义字符编码、导入Java包、指定语言等。常见的页面指令有`contentType`、`pageEncoding`、`import`和`language`。例如: ```jsp ...
### Page Directive 和 Taglib Directive Page Directive用于设置页面级的属性,如导入Java类、指定编码格式等。Taglib Directive则用来导入自定义标签库,使得可以在页面中使用这些标签。 ### JSP2的Include ...
- **JSP Page Directive**:`<%@ page ... %>`, 用于设置页面属性。 - 示例:`<%@ page contentType="text/html;charset=UTF-8" language="java" %>`, 设置内容类型和语言。 - **JSP Include Directive**:`...
- 页面指令(Page Directive):设置页面属性,如语言、导入的包、错误页面等。 - 包含指令(Include Directive):静态或动态地包含其他文件,增强代码复用。 - 复用指令(Taglib Directive):引入自定义标签库...
此外,在每个JSP文件中也可以通过page directive指令来控制是否忽略EL表达式的解析,通过isELIgnored属性来实现。该属性可以设置为"true"或"false",来决定是否忽略EL表达式。例如,通过以下指令可以关闭对EL表达式...
- **Page Directive**: 如 `<%@ page language="java" contentType="text/html; charset=UTF-8" %>`,用于定义页面的基本属性,如语言、内容类型等。 - **Include Directive**: 如 `...
1. **page Directive**:允许导入类、定义servlet的超类、设置页面编码等。例如: ```jsp <%@ page language="java" import="java.util.*,com.example.MyClass" session="false" %> ``` 2. **include Directive**...
**JSP指令** 有三种类型:页指令(page directive)、包含指令(include directive)和标签库指令(taglib directive)。页指令如`<%@ page %>`用来设置整个JSP页面的属性,如语言、导入的包等。包含指令如`...
2. **指令**:JSP提供了三种类型的指令,包括页面指令(page directive)、包含指令(include directive)和标签库指令(taglib directive)。例如,`<%@ page %>`用于设置页面属性,`<jsp:include>`用于动态包含...
1. **页面指令(Page Directive)**:`<%@ page ... %>`,用于设置JSP页面的全局属性,如字符编码、导入的包等。 2. **包含指令(Include Directive)**:`<%@ include file="..." %>`, 静态包含其他文件内容。 3....
3. **JSP指令**:JSP提供三种类型的指令,包括页面指令(page directive)、包含指令(include directive)和标签库指令(taglib directive)。页面指令如`<%@ page %>`用于设置页面属性,包含指令如`<jsp:include>`...
2. **JSP指令**:包括页面指令(page directive)、导入指令(import directive)和包含指令(include directive)。页面指令用于设置整个JSP页面的属性,如`<%@ page %>`, 导入指令用于引入Java类,而包含指令用于...
JSP指令中,最重要的一个是**页面指令(Page Directive)**,它以`<%@ page %>`开始,可以设置多种属性。例如: - `language`属性定义了页面使用的语言,默认是Java。 - `import`属性用于导入所需类和包,多个类或包...
这通过引入`<jsp:directive.page>`、`<jsp:include>`、`<jsp:useBean>`等指令来实现,让页面更清晰,便于设计和维护。 **2. 标准标签库(JSTL)** JSP2.0推荐使用JSTL(JavaServer Pages Standard Tag Library),...
【JSP指令】包括页面指令(Page Directive)、包含指令(Include Directive)和标签库指令(Taglib Directive)。例如,`<%@ page language="java" contentType="text/html; charset=UTF-8" %>`定义了页面的基本属性...