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

 2022-04-28 10:04

A Comparative Study of Web Application Design Models

Using the Java Technologies

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.

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

2 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:

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.

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 are prompt response and reducing the server workload. The server-side input validation should always be performed regardless the presen

全文共24373字,剩余内容已隐藏,支付完成后下载完整资料


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

摘要

Servlet技术在建立可扩展性Web应用中是被应用最广泛的技术。在运用JAVA技术开发Web应用中有四种模型,分别是:Model 1、Model 2、Struts和JavaServer Faces(JSF)。Model 1使用一连串的JSP页面;Model 2采用了模型-视图-控制器(MVC)模式;Struts是一个采用了Model 2设计模型的框架;JSF是一种支持ready-to-use组件来进行快速Web应用开发的新技术。Model 1对于中等和大型的应用来说很难维护,所以不推荐使用。本文通过利用Model 2、Struts和JSF这三种模型分别构建三个不同版本的在线商店应用程序,来比较和评价这三种模型在应用程序开发和性能上的差异。

1.绪论

当今,Web应用是一种展现动态内容的最普遍的方式。构建Web应用有许多种方法,其中最流行的是Servlet技术。这种技术的流行是因为它比CGI、PHP等其他技术更具优越性。然而Servlet对于开发来说还是麻烦的,因为它在传送HTML标签时需要程序员将他们组合成为一个字符串对象,再将这个对象传给浏览器。同样的,对于输出的一个很小的改动也要求Servlet被重新编译。基于这个原因,SUN公司发明了JavaServer Pages(JSP)技术。JSP允许HTML标签和Java代码混合在一起,每个页面将被转化为一个Servlet,一个JSP就是一个Servlet,而且编译将在JSP页面第一次被请求时自动进行,改变输出也不需要重新编译。

另外,通过使用JavaBean和定制标签库,JSP能够将表示与业务逻辑相分离。 现今,基于JAVA的Web应用开发标准是将servlets与JSP结合在一起。随后,出现了许多种设计模型用来构建servlet/JSP应用:Model 1、Model 2、Struts]和JavaServer Faces(JSF)。Model 1和Model 2最早是在JSP规范中被提及的。Model 1只使用JSP而不使用servlet,Model 2则结合了JSP与servlet。Model 1和Model 2的使用是有条件的,Model 1适合与开发原型和非常小的应用,Model 2则是开发中型和大型应用推荐的设计模型。由于Model 2越来越被行业所接受,一个建立Struts框架的开源项目也因此被启动了。Struts通过为Model 2提供了模型-视图-控制器中的控制器来完善Model 2。另外,Struts提供了更好的页面导航管理机制和一些定制标签库,能够进行更快速的开发。尽管它学习难度大,并且,实际上它没有在任何的规范中被定义,但是它还是作为Model 2的一种替代获得了流行。JavaServer Faces是在JCP的JSR-127规范下被建立。Sun公司力推这项技术,希望它能够成为构建Java Web应用的最终模型。JSF最重要的特性是对ready-to-use组件的支持,比如:可扩展用户接口组件、简易的页面导航、输入验证、数据转换和JavaBean管理机制。servlet/JSP程序员面临的问题是选择最合适的设计模型。明显的,JSF在开发时间上提供了更好的解决方案。然而,有些人担心实施JSF的开销所带来的性能下降而不愿采用这种技术。

我们使用Model 2、 Struts和JSF分别构建三个不同版本的在线商店应用,比较的参数是:代码的行数、类的数目和性能测试结果。

我们研究哪种设计模型能够进行最快速的开发。我们评估基于这些模型的应用的性能。我们提供一些建议来完善现有的设计模型,使得开发速度更快。

文章的余下部分组织如下:

第二部分讨论了Web开发中的问题,第三部分解释了三个设计模型如何来解决这些开发问题,第四部分详细介绍了试验所需要的硬件和软件,第五部分给出试验的结果并进行分析,第六部分回顾相关工作,第七部分得出结论并提出了一些改进现有设计模型的建议。

2.Web开发中的问题

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

1.用户接口是在客户浏览器上呈现出的HTML标签。任何在应用中使用的服务器端组件都必须被编码成为正确的HTML标签。除了显示内容和数据外,用户接口还负责接收用户的输入。

2.用户的输入必须要验证。输入的验证有两种类型:服务器端和客户端。顾名思义,服务器端的输入验证是在输入的数据到达服务器后,在服务器上进行的。客户端的输入验证是在浏览器上完成的,一般使用JavaScript或其他脚本语言。利用客户端进行输入验证的好处是反应迅速,而且能够减轻服务器的负载。无论是否存在客户端输入验证,服务器端的输入验证是一定要执行的,因为无法保证用户的浏览器的脚本特性被打开,而且恶意用户能够很轻松的绕过客户端的验证。

3.在基于Java的Web应用中模型对象是以JavaBean的形式出项的。模型对象组成了基于MVC设计模型的模型部分。一个模型对象能够用来绑定一个组件的值,以备下阶段使用。此外,它能够封装需要执行的业务逻辑。

4.大多数的Web应用都包含多个页面,能够使用户从一个页面跳转到另一个页面。所有的基于MVC的设计模式都使用Servlet作为控制部分。这个Servlet也作为进入应用的唯一入口。当前的请求之后哪个页面会被显示取决于请求参数的具体值。管理页面导航是至关重要的。

3.Web应用设计模型

Model 2设计模型是基于模型-视图-控制器(MVC)设计模式的。正如Burbeck所解释的,在MVC中有三个主要模块:控制器,视图和模型。控制器作为应用的中心,所有的用户交互都要通过它。视图包含了应用的显示,而模型用来存储数据和封装应用的业务逻辑。随后,Struts框架提供了一个通用框架能够容易的构建Model 2应用。最主动的是同样使用MVC设计模式的JSF。在之后的章节,我们将来讨论这三种设计模型,并且说明每一种设计模型是怎样来解决之前提到的开发问题。

3.1 Model 2

一个基于Model 2设计模型的Java Web应用有一个作为控制部分的servlet(称为控制器servlet)。所有的请求首先被这个servlet处理,它通过RequestDispatcher对象将请求迅速的分派到合适的视图。在Model 2中视图是通过JSP页面来表现的。JavaBean作为Model 2 的模型部分,用来在应用中存储数据。除了存储数据,JavaBean还用来封装业务逻辑。每个HTTP请求都带有一个行为参数,用来指出哪个视图指派给这个请求。程序员必须在所有的JSP页面中为用户接口编写HTML标签代码,并且编写输入验证代码。此外,模型对象被单独的JSP页面所管理。

3.2 Struts

Struts框架是Model 2设计模型的一个改进。它提供了一个默认的控制器servlet,使得程序员不用非得去编写一个。Struts允许在应用配置文件(一个XML文件)中编写导航规则来减轻页面导航的任务,改变导航规则不需要重新编译。除了更简单的页面导航,Struts还提供了定制标签库来定义标签代表HTML元素。这些标签中的一些用来处理异常,而且Struts支持国际化,能够显示本地化的错误消息。就像Model 2一样,Struts使用JavaBean作为模型。此外,Struts程序员必须编写输入验证代码。

3.3 JSF

JSF同样使用了一个控制器servlet,称为FacesServlet。这个Servlet是整个JSF应用的唯一入口。JSF同样使用JSP页面作为它的视图,使用JavaBean作为模型对象。与Model 2和Struts不同,JSF提供了能够写入JSP页面的ready-to-use的用户接口组件。在JSF应用中的页面的调用,FacesServlet建立了一个组件树来显示JSP页面的请求。大部分的组件还能够触发事件,来构成JSF的事件驱动。对于页面导航,JSF使用了和Struts类似的方法,即允许在一个应用控制文件(XML文件)中定义导航规则。

JSF应用与非JSF的servlet/JSP应用的不同在于JSF是事件驱动的。JSF的用户接口是一个或多个JSP页面,用来服务诸如表单和输入框等Web组件。这些组件以JSF定制标签的形式出现而且能够保存数据。一个组件能够嵌套在另一个组件中,有可能形成一个组件的树状结构。在普通的servlet/JSP应用中,使用JavaBean来存储用户输入的数据。

4.运行环境

以下是我们实验的软硬件详细描述。

4.1 Servlet容器

Java Web应用是在servlet容器中运行的,在应用中它一个引擎,用来处理接踵而来的请求资源的HTTP请求。在这个试验项目中,我们使用Tomcat-一个来自Apache软件基金会的开源的servlet容器,版本号是6.0。基本上,一个servlet容器通过执行下面的任务来处理一个servlet:

  • 创建一个HttpRequest对象
  • 创建一个HttpResponse对象
  • 传递HttpRequest、HttpResponse对象来调用Servlet接口的service方法

4.2 测试用客户端

为了进行性能测试,我们使用同样来自Apache软件基金会的JMeter1.9来模拟多用户。JMeter允许用户选择一定数量的线程来执行测试。每个线程模拟了一个不同的用户。JMeter来能允许我们选择完成一次测试的测试次数。使用JMeter来测试一个Web应用,你只要直接向某个IP地址、上下文路径和端口号发出请求。你也可以将请求参数包含在HTTP请求中。对于一个测试,JMeter将服务器的响应时间以毫秒的形式输出。从响应时间,我们能够得到服务器执行服务的每秒命中次数。

4.3 硬件

为了得到最大的性能度量精度,我们使用不同的计算机来进行应用的测试。运行应用的是一台XP计算机,它的配置如下:Intel Core 1GHz CPU 、1G RAM。测试用客户端是运行JMeter的Windows2000计算机,具体配置如下:Intel Core 1GHz CPU、 1G RAM。

5.结论

我们得到两类实验结果:开发的难易程度和性能。开发的难易程度比较了类的数目和代码的行数。这些数目显示了遵从某个设计模型来开发一个应用的难易程度。一个应用包含较少的类和较少的代码行数说明应用相对而言更容易构建。一个应用包含较多的类说明应用需要花费更多的时间来开发。

性能度量结果是通过比较这两个操作来获得的。查找操作是一个应用中最普通的操作以及浏览操作。

5.1 应用开发的难易程度

就如表1显示的,应用Model 2设计模型需要花费最多的努力,使用Struts能够使问题减轻一点,使用JSF最省力。

表1 应用中类的数目和代码行数

Model 2 设计模型的特点是存在一个控制器servlet和多个JavaBean类(作为模型)及JSP页面(作为视图)。控制器类通过一系列的if语句来负责页面导航规则。Model 2程序员还必须为输入验证编写代码,在这个实验中是通过在内部编写许多定制标签库来完成的。在Model 2设计模型中的其它类是定制标签库,这些标签是用来负责输入验证和数据显示的。实际上,输入验证使用了590行代码,大约是所有代码的30%。

在Struts应用中,控制器servlet是由框架提供的,所以Struts程序员不用编写它,节省了时间。然而,他仍然需要在应用控制文件中编写导航规则,这比编写一个servlet容易些,因为应用控制文件可以用文本编辑器编辑,不必编译。虽然Struts框架提供了错误处理机制,但仍然需要手工编写输入验证。用来进行输入验证的类的数量和代码的行数与Model 2应用的很相似。Struts中其他的类是Action类,用来调度请求到默认的控制servlet。

在JSF中,提供使用验证组件而不用编写输入验证,所以JSF应用开发人员可以跳过这个任务。此外,页面导航和Struts相同,都是使用一个应用控制文件。在JSF中,其他的类是ContextListener、ActionListener和数据库工具类。

5.2 性能度量

对于每一个操作,通过1-10个并发用户,我们来测量服务器的响应时间(以毫秒形式)每个用户在JMeter中设定了一定数量的线程。每次测试进行10次,取平均值。每个操作在下面的章节中讨论。

5.2.1 查询操作

查询操作,其名称或描述与关键字匹配。它将执行一个SQL的SELECT语句。图2比较了三个版本的应用的查询操作。

图2 查询操作的性能比较

在Model 2应用中,对于一个用户,服务器平均的响应时间是173毫秒,对于10个用户是919毫秒。在Struts应用中,相对地,其值是189毫秒和900毫秒,在JSF中则是210毫秒和932毫秒。响应时间随着并发用户数成比例的增加,说明了服务器仍然能够应付装载。

Model 2应用开销最小,所以它的平均性能比Struts和JSF更好。然而,Struts的性能同Model2 的相同,这是因为服务器有足够的内存用来加载运行Struts需要的Strut

全文共8914字,剩余内容已隐藏,支付完成后下载完整资料


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

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

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