基于Myeclipse的签约管理系统的设计与实现外文翻译资料

 2021-11-27 09:11

Part I: Conceptual Reference

Chapter List

Chapter 1: JSP Overview: The Components of a JavaServer Page Chapter 2: Java Servlets

Chapter 3: JavaBeans and JSP Concepts Chapter 4: JDBC and JSP Concepts

Chapter 1: JSP Overview: The Components of a JavaServer Page

Overview

JavaServer Pages, also known as JSPs, are a simple but powerful technology used to generate dynamic HTML on the server side. They are a direct extension of Java servlets and provide a way to separate content generation from content presentation. The JSP engine is just another servlet that is mapped to the extension *.jsp. The following code contains a simple example of a JSP file:

lt;HTMLgt;

lt;BODYgt;

lt;% out.println('HELLO JSP WORLD'); %gt;

lt;/BODYgt;

lt;/HTMLgt;

Its output would look similar to Figure 1.1.

Figure 1.1: Output of the JSP example.

You can see that this document looks like any other HTML document with some added tags containing Java code. The source code is stored in a file called HelloJSPWorld.jsp and copied to the document directory of the Web server. When a request is made for this document, the server recognizes the *.jsp extension and realizes that special handling is required. The first time the file is requested, it is compiled into a servlet object and stored in memory, and the output is sent back to the requesting client. After the first request, the server checks to see whether the *.jsp file has changed. If it has not changed, then the server invokes the previously compiled servlet object. In this chapter and throughout the rest of the book, we will be discussing just how JSPs work and how to use them. Figure 1.2 shows these steps graphically.

Figure 1.2: The steps of a JSP request.

Note A key thing to remember about JSPs is that they are just servlets that are created from a combination of HTML text and Java source code. This means that they contain all the functionality of a normal servlet.

The Components of a JavaServer Page

In this section we are going to cover the components that make up a JavaServer Page. They are discussed in detail in the following sections.

Directives

Directives are JSP elements that provide global information about an entire JSP page. An example would be a directive that indicated the language to be used in compiling a JSP page. The syntax of a directive is as follows:

lt;%@ directive {attribute='value'} %gt;

This states that, for this page directive, assign these values for these attributes. A directive can contain n

number of optional attribute/value pairs.

If we use our previous example for indicating the JSP language, the following line of code would indicate that the JSP language to use would be Java:

lt;%@ page language='java' %gt;

There are three possible directives currently defined by the JSP specification: page, include, and taglib. Each one of these directives and their attributes, if applicable, are defined in the following sections.

The page Directive

The page directive defines information that will be globally available for that JavaServer Page. These page level settings will directly affect the compilation of the JSP. Table 1.1 defines the attributes for the page directive.

Note Because the mandatory attributes are defaulted, you are not required to specify any page directives.

Table 1.1: The Attributes for the page Directive

Attribute

Definition

language='scriptingLanguage'

This attribute tells the server what language will be used to compile the JSP file. Currently Java is the only available language.

extends='className'

This attribute defines the parent class that the JSP generated servlet will extend from.

import='importList'

This attribute defines the list of packages that will be available to this JSP. It will be a comma-separated list of

package names.

session='true|false'

This attribute determines whether the session data will be available to this page. The default is true.

buffer='none|size in kb'

This attribute determines whether the output stream is buffered. The default value is 8KB.

autoFlush='true|false'

This attribute determines whether the output buffer will be flushed automatically, or whether it will raise an exception when the buffer is full. The default is true, which states

that the buffer should be flushed automatically.

isThreadSafe='true|false'

This attribute tells the JSP engine that this page can service more than one request at a time. By default this value is

true; if false, the SingleThreadModel is used.

info='text'

This attribute represents information about the JSP page that can be accessed by the page#39;s

Servlet.getServlet Info() method.

errorPage='error_url'

This attribute represents the relative URL to the JSP page that will handle exceptions.

isErrorPage='true|false'

This attribute states whether or not the JSP page is an

errorPage. The default is false.

contentType='ctinfo'

This attribute represents the MIME type and character set of the response.

The include Directive

The include directive is used to insert text and code at J

第一章: JSP概述:JavaServer页面的组件

Overview概述:

JavaServer Pages,也称为JSP,是一种简单但功能强大的技术,用于在服务器端生成动态HTML。 它们是Java servlet的直接扩展,提供了一种将内容生成与内容呈现分开的方法。 JSP引擎只是另一个映射到扩展名* .jsp的servlet。 以下代码包含JSP文件的简单示例:

lt;HTMLgt;

lt;BODYgt;

lt;% out.println('HELLO JSP WORLD'); %gt;

lt;/BODYgt;

lt;/HTMLgt;

Its output would look similar to Figure 1.1.

图1.1 JSP示例的输出

可以看到此文档看起来像任何其他HTML文档,其中包含一些包含Java代码的标记。 源代码存储在名为HelloJSPWorld.jsp的文件中,并复制到Web服务器的文档目录中。 当对此文档发出请求时,服务器会识别* .jsp扩展名并意识到需要进行特殊处理。 第一次请求文件时,它被编译为servlet对象并存储在内存中,并将输出发送回请求客户端。 在第一次请求之后,服务器检查* .jsp文件是否已更改。 如果它没有改变,那么服务器调用先前编译的servlet对象。 在本章和本书的其余部分中,我们将讨论JSP如何工作以及如何使用它们。 图1.2以图形方式显示了这些步骤。

图1.2 JSP请求的步骤

注意:关于JSP的一个关键事项是它们只是由HTML文本和Java源代码组合创建的servlet。 这意味着它们包含普通servlet的所有功能。

JavaServer页面的组件

在本节中,我们将介绍构成JavaServer Page的组件。 它们将在以下部分中详细讨论。

Directives

指令是JSP元素,提供有关整个JSP页面的全局信息。 一个示例是指示在编译JSP页面时使用的语言的指令。 指令的语法如下:

lt;%@ directive {attribute =“value”}%gt;

这表明,对于此页面指令,请为这些属性分配这些值。 指令可以包含n

可选属性/值对的数量。

如果我们使用前面的示例来指示JSP语言,则以下代码行将指示要使用的JSP语言是Java:

lt;%@ page language =“java”%gt;

JSP规范目前定义了三种可能的指令:page,include和taglib。 如果适用,这些指令及其属性中的每一个都在以下部分中定义。

页面指令

page指令定义将为该JavaServer Page全局可用的信息。 这些页面级别设置将直接影响JSP的编译。 表1.1定义了page指令的属性。

注意由于必需属性是默认的,因此不需要指定任何页面指令。

表1.1:页面指令的属性

The page Directive页面指令

page指令定义将为该JavaServer Page全局可用的信息。 这些页面级别设置将直接影响JSP的编译。 表1.1定义了page指令的属性。

注意由于必需属性是默认的,因此不需要指定任何页面指令。

表1.1:页面指令的属性

属性

定义

language='scriptingLanguage'

该属性告诉服务器将使用什么语言来编译JSP文件。目前,Java是唯一可用的语言。

extends='className'

此属性定义JSP生成的servlet将从中扩展的父类。

import='importList'

此属性定义此JSP可用的包列表。 它将是一个以逗号分隔的列表包名称。

session='true|false'

此属性确定会话数据是否可用于此页面。 默认值为true。

buffer='none|size in kb'

此属性确定是否缓冲输出流。 默认值为8KB。

autoFlush='true|false'

此属性确定是自动刷新输出缓冲区,还是在缓冲区已满时是否引发异常。 默认值为true,表示状态应该自动刷新缓冲区。

isThreadSafe='true|false'

此属性告诉JSP引擎该页面一次可以为多个请求提供服务。 默认情况下,此值为true; 如果为false,则使用SingleThreadModel.

info='text'

此属性表示有关页面可以访问的JSP页面的信息

Servlet.getServlet Info()方法。

errorPage='error_url'

此属性表示将处理异常的JSP页面的相对URL。

isErrorPage='true|false'

此属性指出JSP页面是否为的errorPage。 默认值为false。

contentType='ctinfo'

此属性表示响应的MIME类型和字符集。

include指令

include指令用于在JSP转换时插入文本和代码。 包含的语法

指令如下:

lt;%@ include file =“relativeURLspec”%gt;

文件属性指向的文件可以引用普通文本HTML文件,也可以引用JSP文件,该文件将在转换时进行评估。注意:目前,JSP 1.1规范没有定义的方法来通知JSP引擎所包含的JSP文件已更改。

taglib指令

最新版本的JSP规范定义了一种扩展当前JSP标记集的机制。 它通过创建一组称为标记库的自定义标记来实现此目的。 这就是taglib所指出的。 taglib指令声明该页面使用自定义标记,唯一地命名定义它们的标记库,并关联标记前缀以区分这些标记的使用。 taglib指令的语法如下:

lt;%@ taglib uri =“tagLibraryURI”prefix =“tagPrefix”%gt;

如表1.2中描述了taglib属性。

表1.2:taglib指令的属性

属性

定义

uri

此属性引用唯一命名自定义标记集的URI。

prefix

此属性定义用于区分自定义标记实例的前缀字符串。

操作

动作提供了一个抽象,可用于轻松封装常见任务。 它们通常创建或操作对象,通常是JavaBeans。 JSP技术提供了一些标准操作。 这些操作在以下部分中定义。

lt;jsp:useBeangt;

lt;jsp:useBeangt;操作通过相同ID的新声明脚本变量将定义的JavaBean实例与给定范围和ID相关联。 第7章“JavaBeans和JSP概念”将更详细地介绍lt;jsp:useBeangt;操作。

lt;jsp:setPropertygt;

lt;jsp:setPropertygt;操作设置bean属性的值。 lt;jsp:setPropertygt;操作将在第3章中详细介绍。

lt;jsp:getPropertygt;

lt;jsp:getPropertygt;操作获取引用的bean实例的属性的值,将其转换为java.lang.String,并将其放入隐式out对象中。 第3章将详细介绍此操作。

lt;jsp:includegt;

lt;jsp:includegt;操作提供了一种在当前JSP页面中包含其他静态和动态资源的机制。 此操作的语法如下:

lt;jsp:include page =“urlSpec”flush =“true”/gt;

lt;jsp:include page =“urlSpec”flush =“true”gt;

{jsp:param ... /gt;}

lt;/ JSP:includegt;

第一个语法示例说明了请求时包含,而第二个语法示例包含一个param子元素列表,这些子元素用于为包含目的而争论请求。 表1.3包含lt;jsp:includegt;操作的属性及其描述。

表1.3:lt;jsp:includegt; Action的属性

属性

定义

page

此属性表示要包括的资源的相对URL。

flush

此属性表示强制布尔值,表示是否应刷新缓冲区。

lt;jsp:forwardgt;

lt;jsp:forwardgt;操作使JSP引擎能够在运行时将当前请求分派给静态资源,servlet或其他JSP。 此操作的外观有效地终止了当前页面的执行。

注意lt;jsp:forwardgt;操作可以包含lt;jsp:paramgt;子属性。 这些子属性为要用于转发的请求中的参数提供值。

lt;jsp:forwardgt;操作的语法如下:

lt;jsp:forward page =“relativeURLspec”/gt;

lt;jsp:forward page = relativeURLspec“gt;

{lt;jsp:param ... /gt;}

lt;/ JSP:forward gt;

表1.4包含lt;jsp:forwardgt;操作的单个属性及其描述。

Table 1.4: The Attribute for the lt;jsp:forwardgt; Action

属性

定于

page

此属性表示目标的相对URL转发。

lt;jsp:paramgt;

lt;jsp:paramgt;操作用于提供标记/值对信息,方法是将它们包含为lt;jsp:includegt;,lt;jsp:forwardgt;和lt;jsp:plugingt;操作的子属性。 的语法

lt;jsp:paramgt;动作如下:

lt;JSP:params gt;

lt;jsp:param name =“paramName”value =“paramValue”gt;

lt;/ JSP:params gt;Table 1.5 contains the attributes and their descriptions for the lt;jsp:paramgt; action.

表1.5:lt;jsp:paramgt;操作的属性

属性

定义

name

此属性表示要引用的参数的名称。

value

原文和译文剩余内容已隐藏,您需要先支付 30元 才能查看原文和译文全部内容!立即支付

以上是毕业论文外文翻译,课题毕业论文、任务书、文献综述、开题报告、程序设计、图纸设计等资料可联系客服协助查找。