`
jayjayjaylun
  • 浏览: 90016 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

Page Directive

    博客分类:
  • web
阅读更多
 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页面中使用,不能跨页调用
分享到:
评论

相关推荐

    JSP By Example

    - **Page Directive**:通过`&lt;%@ page info="a hello world example" %&gt;`定义了页面信息描述。 - **Body Content**:在页面主体部分添加动态内容。 #### 总结 通过本章节的学习,你不仅了解了JSP的基本语法结构...

    适合初学者的zk开发文档pdf

    8. **页面指令(The page Directive)**:定义页面的基本属性,如标题、编码、错误处理策略等。 9. **根属性指令(The root-attributes Directive)**:用于设置页面根元素的属性,如ID、类名等。 10. **标签库...

    JSP基本语法.ppt

    1. **网页指令(The page directive)**:用于定义JSP页面的属性,如编程语言、继承的Servlet类、导入的Java包等。例如: ```jsp &lt;%@ page language="Java" extends="HttpServlet" import="java.io.*, java.util....

    JSP Simple Examples

    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 ...

    JSP动作和指令.ppt

    1. **Page Directive**: - `language`: 指定JSP页面的脚本语言,如`"java"`。 - `extends`: 定义JSP页面继承自哪个Servlet类。 - `import`: 引入Java类库,例如`"java.util.*"`。 - `buffer`: 控制响应缓冲区的...

    JavaWeb程序设计入门课件JSP指令共5页.pdf.z

    1. **页面指令**(Page Directive):页面指令用于设置整个JSP页面的属性,例如定义字符编码、导入Java包、指定语言等。常见的页面指令有`contentType`、`pageEncoding`、`import`和`language`。例如: ```jsp ...

    JSP2 编程指南:从初学者到专家

    ### Page Directive 和 Taglib Directive Page Directive用于设置页面级的属性,如导入Java类、指定编码格式等。Taglib Directive则用来导入自定义标签库,使得可以在页面中使用这些标签。 ### JSP2的Include ...

    jsp入门教程

    - **JSP Page Directive**:`&lt;%@ page ... %&gt;`, 用于设置页面属性。 - 示例:`&lt;%@ page contentType="text/html;charset=UTF-8" language="java" %&gt;`, 设置内容类型和语言。 - **JSP Include Directive**:`...

    jsp网络编程——源文件(01——05)

    - 页面指令(Page Directive):设置页面属性,如语言、导入的包、错误页面等。 - 包含指令(Include Directive):静态或动态地包含其他文件,增强代码复用。 - 复用指令(Taglib Directive):引入自定义标签库...

    jsp页面中EL表达式被当成字符串处理不显示值问题的解决方法

    此外,在每个JSP文件中也可以通过page directive指令来控制是否忽略EL表达式的解析,通过isELIgnored属性来实现。该属性可以设置为"true"或"false",来决定是否忽略EL表达式。例如,通过以下指令可以关闭对EL表达式...

    学号姓名-实验4.doc

    - **Page Directive**: 如 `&lt;%@ page language="java" contentType="text/html; charset=UTF-8" %&gt;`,用于定义页面的基本属性,如语言、内容类型等。 - **Include Directive**: 如 `...

    JSP应用技巧及心得---数据库的链接

    1. **page Directive**:允许导入类、定义servlet的超类、设置页面编码等。例如: ```jsp &lt;%@ page language="java" import="java.util.*,com.example.MyClass" session="false" %&gt; ``` 2. **include Directive**...

    很好的jsp课件,分享给大家,很好用哦!

    **JSP指令** 有三种类型:页指令(page directive)、包含指令(include directive)和标签库指令(taglib directive)。页指令如`&lt;%@ page %&gt;`用来设置整个JSP页面的属性,如语言、导入的包等。包含指令如`...

    网上书店系统(JSP)

    2. **指令**:JSP提供了三种类型的指令,包括页面指令(page directive)、包含指令(include directive)和标签库指令(taglib directive)。例如,`&lt;%@ page %&gt;`用于设置页面属性,`&lt;jsp:include&gt;`用于动态包含...

    JSP编程技巧(自学手册)

    1. **页面指令(Page Directive)**:`&lt;%@ page ... %&gt;`,用于设置JSP页面的全局属性,如字符编码、导入的包等。 2. **包含指令(Include Directive)**:`&lt;%@ include file="..." %&gt;`, 静态包含其他文件内容。 3....

    jsp--jsp的初步认识

    3. **JSP指令**:JSP提供三种类型的指令,包括页面指令(page directive)、包含指令(include directive)和标签库指令(taglib directive)。页面指令如`&lt;%@ page %&gt;`用于设置页面属性,包含指令如`&lt;jsp:include&gt;`...

    JSP网络编程从基础到实践(第2版).rar

    2. **JSP指令**:包括页面指令(page directive)、导入指令(import directive)和包含指令(include directive)。页面指令用于设置整个JSP页面的属性,如`&lt;%@ page %&gt;`, 导入指令用于引入Java类,而包含指令用于...

    JSP Status.ppt

    JSP指令中,最重要的一个是**页面指令(Page Directive)**,它以`&lt;%@ page %&gt;`开始,可以设置多种属性。例如: - `language`属性定义了页面使用的语言,默认是Java。 - `import`属性用于导入所需类和包,多个类或包...

    JSP2.0技术手册

    这通过引入`&lt;jsp:directive.page&gt;`、`&lt;jsp:include&gt;`、`&lt;jsp:useBean&gt;`等指令来实现,让页面更清晰,便于设计和维护。 **2. 标准标签库(JSTL)** JSP2.0推荐使用JSTL(JavaServer Pages Standard Tag Library),...

    jsp视频学习教程地址

    【JSP指令】包括页面指令(Page Directive)、包含指令(Include Directive)和标签库指令(Taglib Directive)。例如,`&lt;%@ page language="java" contentType="text/html; charset=UTF-8" %&gt;`定义了页面的基本属性...

Global site tag (gtag.js) - Google Analytics