基于Java技术的Web应用程序设计模型的比较研究外文翻译资料

 2022-08-11 09:08

A Comparative Study of Web Application Design Models Using the Java Technologies

Budi Kurniawan and Jingling Xue

School of Computer Science and Engineering

University of New South Wales Sydney, NSW 2052, Australia

Abstract.

The Servlet technology has been the most widely used technology for building scalable Web applications. In the events, there are four design models for developing Web applications using the Java technologies: Model 1, Model2, Struts, and JavaServer Faces (JSF). Model 1 employs a series of JSP pages; Model 2 adopts the Model-View-Controller pattern; Struts is a framework employing the Model 2 design model; and JSF is a new technology that supports ready-to-use components for rapid Web application development. Model 1 is not recommended for medium-sized and large applications as it introduces maintenance nightmare. This paper compares and evaluates the ease of application development and the performance of the three design models (Model 2, Struts, and JSF) by building three versions of an online store application using each of the three design models, respectively.

Introduction

Today, Web applications are the most common applications for presenting dynamic

contents. There are a number of technologies for building Web applications, the most popular of which is the Servlet technology . This technology gains its popularity from its superiority over other technologies such as CGI and PHP .Servlets are cumbersome to develop, however, because sending HTML tags requires the programmer to compose them into a String object and send this object to the browser. Also, a minor change to the output requires the servlet to be recompiled. To address this issue, Sun Microsystems invented JavaServer Pages (JSP) . JSP allows HTML tags to be intertwined with Java code and each page is translated into a servlet. A JSP page is a servlet. However, compilation occurs automatically when the page is first requested. As a result, changing the output does not need recompilation. In addition, JSP enables the separation of presentation from the business logic through the use of JavaBeans and custom tag libraries. The norm now in developing Javabased Web applications is to use servlets along with JavaServer Pages.

In the later development, there are a number of design models for building servlet/JSP applications: Model 1, Model 2, Struts , and JSF . Model 1 and Model 2 were first mentioned in the early specifications of JSP. Model 1 strictly uses JSP pages, with no servlets, and Model 2 uses the combination of both servlets and JSP pages. The terms of Model 1 and Model 2 have been used ever since. Model 1 is suitable for prototypes and very small applications, and Model 2 is the recommended design model for medium sized and large applications.

As Model 2 gained more acceptances in the industry, an open source initiative to build the Struts Framework was initiated. Struts perfects Model 2 by providing the controller part of the Model-View-Controller of Model 2. In addition, Struts provides better page navigation management and several custom tag libraries for more rapid development. Despite its steep learning curve and the fact that it was never defined in any specification, Struts has been gaining popularity as the alternative to Model 2.

JavaServer Faces [6] is built under the Java Community Process under JSR-127. Sun Microsystems proposed this technology in the hope that JSF will be the ultimate model for building Java Web applications. The most important feature of JSF is the availability of ready-to-use components such as extensible UI components, easy page navigation, input validators, data converters and JavaBeans management.

The problem facing servlet/JSP programmers are to choose the most appropriate design model. Clearly, JSF provides a better solution in regard to development time.However, some people are not sanguine to adopt this technology for fear of performance penalty due to the overhead of the JSF implementation.

We build three versions of an online store application named BuyDirect using Model 2, Struts and JSF. The parameters compared are the number of lines of code,the number of classes, and the performance measurement results. We investigate which of the design models allows the most rapid development process. We evaluate the performances of the applications built upon these models. We provide some suggestions to perfect the existing design models to make development more rapid.

The rest of the paper is organised as follows. Section 2 discusses the issues in Web development. Section 3 explains how the three design models address these development issues. Section 4 provides the details of the hardware and software used in these experiments. Section 5 presents the experiment results and analysis. Section 6 reviews the related work. Section 7 concludes by offering some suggestions to improve the existing design models.

Java Web Development Issues

All Java Web development uses the Servlet technology as the underlying technology.

As such, all Java Web applications have certain issues that need to be addressed:

minus; User Interface. The user interface is what the client browser renders as HTML tags. Any server-side component used in the application must be encoded into the corresponding HTML elements. Besides for displaying the content and data, the user interface is also responsible in receiving input from the user.

minus; Input Validation. User input needs to be validated. There are two types of input validation, server-side and client-side. As the name implies, the server-side input validation is performed on the server after the input reaches the server. Client-side input validation is done on the browser, usually by using JavaScript or other scripting languages. The advantages of using client-side input validation

剩余内容已隐藏,支付完成后下载完整资料


基于Java技术的Web应用程序设计模型的比较研究

摘要

Servlet技术已经成为构建可扩展性Web应用程序时应用最广泛的技术。在运用Java技术开发Web应用程序中有四种设计模型,分别为:Model 1, Model 2,Struts和JavaServer Faces(JSF)。Model 1使用了一系列JSP页面;Model 2采用了模型-视图-控制器模式;Struts是一个采用Model 2设计模型的框架;JSF是一项支持使用随时可用的组件来进行快速Web应用程序开发的新技术。Model 1不建议用于中型和大型应用,因为它很难维护。本文通过利用Model 2、Struts和JSF这三种设计模型分别构建三个版本的在线商店应用程序,以比较、评估这三种设计模型在应用程序开发时的难易程度和性能上的差异。

1.引言

如今,Web应用程序是一种呈现动态内容的最普遍方式。构建Web应用程序有很多的技术方法,其中最流行的是Servlet技术。它广为流传的原因是因为该技术具有其他技术(如CGI和PHP)无可比拟的优越性。但是,Servlet的开发是很麻烦的,因为它发送HTML标签时需要程序员将它们组合成String对象,再将这个对象发送给浏览器。同样,一个输出的微小改动也要求重新编译Servlet。为了解决这个问题,Sun Microsystems发明了JavaServer Pages (JSP)。JSP允许HTML标记和Java代码交织在一起,并且每个页面都被转化成一个Servlet。一个JSP就是一个servlet,而且页面第一次被请求时,编译便会自动发送,并且更改输出不需要重新编译。另外,JSP通过使用JavaBean和自定义标签库,使得表示与业务逻辑分离。现在,基于Java的Web应用程序的开发标准是将servlet与JavaServer Pages结合在一起。

在之后的开发中,有许多用于构建servlet/JSP应用程序的设计模型:Model 1, Model 2,Struts 和JSF。Model 1和Model 2在早期JSP规范中最先被提到。Model 1严格使用JSP页面而不使用servlet,Model 2则是servlet和JSP页面的结合。自此后Model 1和Model 2便一直被使用。但是,Model 1适用于开发原型和非常小的应用程序,Model 2则是中型和大型应用程序的推荐设计模型。

由于Model 2在业界获得越来越多的认可,一个构建Struts框架的开源计划便开始启动了。 Struts通过为Model 2提供Model-View-Controller的控制器部分来完善Model2。此外,Struts提供了更好的页面导航管理和多个自定义标签库,以加快开发速度。 尽管它学习难度大,并且它从未在任何规范中被定义,但Struts作为Model 2的替代品已越来越受欢迎。

JavaServer Faces [6]是在JSR-127下的Java Community Process规范下下构建的。Sun Microsystems力推这项技术,希望JSF成为构建Java Web应用程序的最终模型。JSF的最重要的功能是提供了现成的组件,例如可扩展用户界面组件,简单的页面导航,输入验证器,数据转换器和JavaBeans管理机制。

Servlet/JSP程序员面临的问题是选择最合适的设计模型。显然,JSF在开发时间方面提供了更好的解决方案。但是,有些人考虑到实现JSF的开销而不愿意采用这种技术。

我们使用Model 2,Struts和JSF构建了名为BuyDirect的三个版本的在线商店应用程序。比较的参数是代码行数,类的数目和性能测量结果。 我们研究哪种设计模型可以最快速地进行开发。我们评估基于这些模型的应用程序的性能,并提供一些建议以完善现有的设计模型,使得其开发更加迅速。

本文的其余部分安排如下:第2部分讨论Web开发中的问题。第3部分说明三种设计模型如何来解决这些开发问题。第4部分详细介绍这些实验中使用的硬件和软件。第5部分介绍实验结果并进行分析。第6部分回顾相关工作。第7部分总结并提出一些改进现有的设计模型的建议。

2.Java Web开发的问题

所有Java Web开发都使用Servlet技术作为基础技术。因此,所有Java Web应用程序都有一些问题需要解决:

-用户界面。 用户界面是客户端浏览器上呈现出HTML标签的界面。 应用程序中使用的任何服务器端组件都必须编码为相应的HTML元素。 除了用于显示内容和数据之外,用户界面还负责接收来自用户的输入。

-输入验证。 用户输入需要验证。 输入验证有两种类型,服务器端和客户端。 顾名思义,服务器端输入验证是在输入到达服务器后在服务器上执行的。 客户端的输入验证通常使用JavaScript或其他脚本语言在浏览器上完成。 使用客户端输入验证的优点是其响应迅速并能减少服务器工作量。 无论是否存在客户端验证,都应执行服务器端输入验证,因为无法保证用户浏览器的脚本功能已开启,并且恶意用户能够轻松的避开客户端的验证。

-模型对象。 基于Java的Web应用程序中的模型对象采用的是JavaBeans形式。 模型对象构成了基于MVC的设计模型的模型部分。 一个模型对象可用于绑定要在后期阶段使用的组件值。另外,它可以封装处理所需要的业务逻辑。

-页面导航。 大多数Web应用程序都有多个页面,用户可以从一个页面跳转到另一个页面。 所有基于MVC的设计模型都使用servlet作为控制器部分。 该servlet也是应用程序的唯一入口。 当前请求之后所显示的页面取决于请求参数的值。 因此管理页面导航是至关重要的。

3.Web应用程序设计模型

Model 2设计模型基于Model-View-Controller(MVC)设计模式。 正如Burbeck [1]所解释的那样,MVC中有三个主要模块:控制器,视图和模型。 控制器作为应用程序的中心,所有用户交互都要通过控制器。 视图包含了应用程序的显示部分,而模型用于存储数据和封装应用程序的业务逻辑。 在之后的开发中,Struts框架提供了一个通用框架来轻松构建Model 2应用程序。 最后的一个举措是同样采用了MVC设计模式的JavaServer Faces。

在之后各部分内容中,我们将讨论这三种设计模型,并说明每种设计模型是如何解决前面内容中所提出的开发问题的。

3.1 Model 2

基于Model 2设计模型的Java Web应用程序都具有一个Servlet(称为Controller Servlet),它充当Controller的一部分。 所有请求都首先由该Servlet处理,它通过RequestDispatcher对象将请求分派到相应的视图。 Model2设计模型中的视图是由JSP页面表示的。 为了存储数据,模型2应用程序使用JavaBeans(它们是应用程序的模型部分)。 除了存储数据之外,JavaBeans还用来封装业务逻辑。 每个HTTP请求都带有一个行为参数,该参数指示将请求分派到哪个视图。 程序员必须在应用程序的所有JSP页面中为用户界面的HTML标签编写代码,并编写输入验证代码。 此外,模型对象由单独的JSP页面所管理。

3.2 Struts

Struts框架是对Model 2设计模型的改进。它提供了一个默认的Controller Servlet,使得用户不必编写和编译它。Struts通过允许在应用程序配置文件(XML文档)中显示导航规则来减轻页面导航的任务。更改导航规则不需要重新编译Java servlet类。除了更简单的页面导航之外,Struts还提供了自定义标签库,这些库定义了表示HTML元素的标签。这些标签中的一些用于处理异常,因此Struts能够显示本地化的错误消息以支持国际化。就像Model 2设计模型一样,Struts应用程序使用JavaBeans作为其模型。另外,Struts程序员必须编写自己的输入验证代码。

3.3 JSF

JSF同样采用了一个称为FacesServlet的控制器Servlet。该servlet是JSF应用程序的唯一入口。 JSF还使用JSP页面作为它的视图,并使用JavaBeans作为它的模型对象。但是,与Model 2和Struts不同,JSF提供了可以在JSP页面上编写的即用型用户界面组件。调用JSF应用程序的页面后,FacesServlet会构造一个组件树,用来显示所请求的JSP页面。一些组件还可以触发事件,以造成JSF事件驱动。对于页面导航,JSF使用了与Struts类似的方法,即允许在应用程序配置文件(同样是XML文档)中定义导航规则。

JSF应用程序与非JSF的servlet/JSP应用程序的区别在于JSF应用程序是事件驱动的。JSF应用程序的用户界面是一个或多个JSP页面,这些页面承载Web组件,例如表单和输入框。这些组件由JSF定制标记所表示,并且可以保存数据。 一个组件可以嵌套在另一个组件中,并且可以绘制一棵组件树。就像在普通的servlet/JSP应用程序中使用JavaBeans存储用户输入的数据一样。

4.实验装置

我们实验的软、硬件详细信息描述如下:

4.1网上商店申请

本研究中的网上商店应用有三个版本:Model 2,Struts和JSF。它们都被命名为BuyDirect—一个销售电子产品的在线商店。 该应用程序具有以下功能:

-根据产品名称或说明来搜索某些产品。

-按类别来浏览产品的列表。

-查看产品的详细信息。

-将产品放入购物车。

-查看购物车。

-结账并下订单。

此应用程序代表最常见的Web应用程序,它能提供以下功能:

-在数据库中搜索某些信息。

-浏览数据库中的数据。

-执行数据库事务。

数据被存储在MySQL数据库中。所使用的图表及它们之间的关系如图1所示。

4.2.Servlet容器

Java Web应用程序是在servlet容器中运行的,该容器是一个引擎,用来处理应用程序中资源的传入HTTP请求。 在此研究项目中,我们使用Tomcat-这是Apache软件提供的开源servlet容器基础。 我们使用的版本是5.02 [11]。

基本上,一个Servlet容器通过执行以下任务来一个Servlet:

-创建HttpRequest对象。

-创建HttpResponse对象。

-通过传递HttpRequest和HttpResponse对象来调用Servlet接口的service方法。

4.3.测试客户

为了进行性能测试,我们使用同样来自Apache Software Foundation的JMeter 1.9 [9]来模拟多个用户。 JMeter允许用户选择执行测试的线程数目。 每个线程模拟一个不同的用户。 JMeter还允许我们选择要进行测试的次数。 要使用JMeter来测试一个Web应用程序,你只要将请求定向到某些IP地址,上下文路径和端口号。 你还可以指定要求包含在每个HTTP请求中的请求参数。 对于一个测试,JMeter将服务器测试的响应时间以毫秒为单位输出。 从响应时间,我们可以得出服务器执行服务的每秒命中次数。

4.4.硬件

为了获得最大的性能测量精度,我们使用不同的计算机来运行应用程序并进行测试。 运行该应用程序的计算机是一台Linux计算机,它的配置如下:具有256MB RAM的Intel Pentium III 750MHz CPU。 运行测试客户端的计算机是运行JMeter的Windows 2000计算机,该计算机配置如下:具有256MB RAM的Intel Pentium III 850MHz CPU。

5.实验结果

我们获得两类实验结果:开发的难易程度和性能。难易程度类别比较了类数和代码行数。这些数字表明了遵循特定的设计模型来开发应用程序的难易程度。类数较少或代码行数较少表示该应用程序相对较容易构建。具有更多类的表明该应用程序需要花费更多的时间来开发。

通过比较每个版本的网上商店应用程序中的三个操作获得性能评估结果:搜索,浏览和购物。搜索操作是此类应用程序中最常见的操作。浏览操作按类别显示产品,而购物操作则是所有产品中最复杂的操作。它包括填写“订单”表单,然后将购物车中的产品插入数据库。产品插入期间数据库被锁定,因此所有购物商品都存储在数据库中,或者都不存在。

5.1应用程序开发的难易程度

如表1所示,实现Model2设计模型需要花费最大的精力,使用Struts能够稍微减轻问题,而使用JSF则可以最大程度地节省开发成本。

图表 1研究的应用程序的类数和行数

Model2设计模型的特征是存在一个Controller servlet和许多JavaBeans类(作为Model)和JSP页面(作为View)。Controller Servlet为了页面导航规则而负责采用一系列if语句。Model 2应用

剩余内容已隐藏,支付完成后下载完整资料


资料编号:[237733],资料为PDF文档或Word文档,PDF文档可免费转换为Word

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

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