1、毕业设计(论文)外文文献翻译专业学生姓名班级学号指引教师外文资料名称: An Overview of Servlet and JSP Technology 外文资料出处: Internet 附 件: 1.外文资料翻译译文 2.外文原文 指引教师评语: 签名: 年 月 日Servlet和JSP技术简述Nagle and WiegleyXX译摘要:Servlet程序在服务器端运营,动态地生成Web页面与老式CGI和许多其她类似CGI技术相比,Java Servlet具备更高效率,更容易使用,功能更强大,具备更好可移植性,更节约投资。核心字:JSP技术,Servlet,HTTP服务1.1Servle
2、t功能Servlets是运营在Web或应用服务器上Java程序,它是一种中间层,负责连接来自Web浏览器或其她HTTP客户程序祈求和HTTP服务器上数据库或应用程序。Servlet工作是执行西门任务,如图1.1所示 。图1.1Web中间件作用(1) 读取客户发送显式数据。最后顾客普通在页面HTML表单中输入这些数据。然而,数据尚有也许来自applet或定制HTTP客户程序。(2) 读取由浏览器发送隐式祈求数据。图1.1中显示了一条从客户端到Web服务器单箭头,但事实上从客户端传送到Web服务器数据有两种,它们分别为顾客在表单中输入显式数据,以及后台HTTP信息。两种数据都很重要。HTTP信息涉
3、及cookie、浏览器所能辨认媒体类型和压缩模式等。(3) 生成成果。这个过程也许需要访问数据库、执行RMI或EJB调用、调用Web服务,或者直接计算得出相应响应。实际数据也许存储在关系型数据库中。该数据库也许不理解HTTP,或者不能返回HTML形式成果,所有Web浏览器不能直接与数据库进行会话。虽然它可以做到这一点,为了安全上考虑,咱们也不但愿让它这样做。相应大多数其她应用程序,也存在类似问题。因而,咱们需要Web中间层从HTTP流中提取输入数据,与应用程序会话,并将成果嵌入到文档中。(4) 向客户发送显式数据(即文档)。这个文档可以用各种格式发送,涉及文本(HTML或XML),二进制(GI
4、F图),甚至可以式建立在其她底层格式之上压缩格式,如gzip。但是,到当前为止,HTML式最惯用格式,故而servelt和JSP重要任务之一就式将成果包装到HTML中。(5) 发送隐式HTTP响应数据。图1.1中显示了一条从Web中间层到客户端单箭头。但是,实际发送数据有两种:文档自身,以及后台HTTP信息。同样,两种数据对开发来说都式至关重要。HTTP响应数据发送过程涉及告知浏览器或其她客户程序所返回文档类型(如HTML),设立cookie和缓存参数,以及其她类似任务。1.2动态构建网页因素预先建立文档可以满足客户许多祈求,服务器无需调用servlet就可以解决这些祈求。然而,许多状况下静态
5、成果不能满足规定,咱们需要针对每个祈求生成一种页面。实时构建页面理由有诸各种:1、网页基于客户发送数据。例如,搜索引擎生成页面,以及在线商店订单确认页面,都要针对特定顾客祈求而产生。在没有读取到顾客提交数据之前,咱们不懂得应当显示什么。要记住,顾客提交两种类型数据:显示(即HTML表单数据)和隐式(即HTTP祈求报头)。两种输入都可用来构建输出页面。基于cookie值针对详细顾客构建页面状况特别普遍。2、页面由频繁变化数据导出。如果页面需要依照每个详细祈求做出相应变化,固然需要在祈求发生时构建响应。但是,如果页面周期性地变化,咱们可以用两种方式来解决它:周期性地在服务器上构建新页面(和客户祈求
6、无关),或者仅仅在顾客祈求该页面时再构建。详细应当采用哪种方式要依照详细状况而定,但后一种方式经常更为以便,由于它只需简朴地等待顾客祈求。例如,天气预报或新闻网站也许会动态地构建页面,也有也许会返回之前构建页面(如果它还是最新话)。3、页面中使用了来自公司数据库或其她数据库断数据源信息。如果数据存储在数据库中,那么,虽然客户端使用动态Web内容,例如applet,咱们仍旧需要执行服务器端解决。想象如下,如果一种搜索引擎网站完全使用applet,那么顾客将会看到:“正在下载50TBapplet,请等待!”。显然,这样很愚蠢;这种状况下,咱们需要与数据库进行会话。从客户端到Web层再到数据库(三层
7、构造),要比从applet直接到数据库(二层构造)更灵活,也更安全,而性能上损失很少甚至没有。毕竟数据库调用普通是对速度影响最大环节,因而,通过中间层可以执行高速缓存和连接共享。理论上讲,servelt并非只用于解决HTTP祈求Web服务器或应用服务器,它同样可以用于其她类型服务器。例如,servlet可以嵌入到FTP或邮件服务器中,扩展她们功能。并且,用于会话启动合同服务器servlet API近来已经被原则化(参见)。但在实践中,servelt这种用法尚不流行,在此,咱们只阐述HTTP Servlet。1.3 Servlet相对于“老式”CGI长处和老式CGI及许多类CGI技术相比,Jav
8、a servelt效率更高、更易用、更强大、更容易移植、更安全、也更便宜。1、效率应用老式CGI,针对每个HTTP祈求都用启动一种新进程。如果CGI程序自身相对比较简短,那么启动进程开销会占用大某些执行时间。而使用servelt,Java虚拟机会始终运营,并用轻量级Java线程解决每个祈求,而非重量级操作系统进程。类似地,应用老式CGI技术,如果存在对同一CGI程序N个祈求,那么CGI程序代码会载入内存N次。同样状况,如果使用servlet则启动N个线程,单仅仅载入servlet类单一副本。这种方式减少了服务器内存需求,通过实例化更少对象从而节约了时间。最后,当CGI程序结束对祈求解决之后,程
9、序结束。这种方式难以缓存计算成果,保持数据库连接打开,或是执行依托持续性数据其她优化。然而,servelt会始终停留在内存中(虽然祈求解决完毕),因而可以直接存储客户祈求之间任意复杂数据。2、便利Servelt提供大量基本构造,可以自动分析和解码HTML表单数据,读取和设立HTTP报头,解决cookie,跟踪会话,以及其她次类高档功能。而在CGI中,大某些工作都需要咱们资金完毕。此外,如果您已经理解了Java编程语言,为什么尚有学校Perl呢?您已经承认应用Java技术编写代码要比Visual Basic,VBScript或C编写代码更可靠,且更易重用,为什么尚有倒退回去选取那些语言来开发服务
10、器端程序呢?3、强大Servlet支持常规CGI难以实现或主线不能实现几项功能。Servlet可以直接于Web服务器对话,而常规CGI程序做不到这一点,至少在不使用服务器专有API状况下是这样。例如,与Web服务器通信使得讲相对URL转换成详细途径名变得更为容易。各种servelt还可以共享数据,从而易于实现数据库连接共享和类似资源共享优化。Servelt还能维护祈求之间信息,使得诸如会话跟踪和计算成果缓存等技术变得更为简朴。4、可移植性Servelt使用Java编程语言,并且遵循原则API。所有重要Web服务器。事实上都直接或通过插件支持servlet。因而。为Macromedia JRun
11、编写servlet,可以不通过任何修改地在Apache Tomcat,Microsoft Internet Information Server,IBM WebSphere 。iPlanet Enterprise Server。Oracle9i AS 或者StrNine WebStar上运营。她们是java2平台公司版一某些,因此对servlet支持越来越普遍。5、便宜对于开发用网站、低容量或中档容量网站布置,有大量免费或极为便宜Web服务器可供选取。因而,通过使用servelt和jsp,咱们可以从免费或便宜服务器开始,在项目获得初步成功后,在移植到更高性能或高档管理工具昂贵服务器上。这与其她
12、CGI方案形成鲜明对比,这些CGI方案在初期都需要为购买专利软件包投入大量资金。价格和可移植性在某种限度上是互有关联。例如,Marty记录了所有通过电子邮件向她发送问题读者所在国。印度接近列表顶端,也许仅次于美国。Marty曾在马尼拉讲授过jsp和servlet培训课程,那儿对servelt和jsp技术抱很大兴趣。那么,为什么印度和菲律宾都对这项技术着呢感兴趣呢?咱们推测答案也许分两某些。一方面,这两个国家都拥有大量训练有素软件开发人员。另一方面,这两个国家货币对美元汇率都极为不利。因而,从美国公司那里购买专用Web服务器会消耗掉项目大某些前期资金。但是,使用servlet 和JSP,她们可以
13、从免费服务器开始:Apache Tomcat。项目获得成功之后,她们可以转移到性能更高、管理更容易,但需要付费服务器。她们servelt和jsp不需要重写编写。如果她们项目变得更庞大,她们或许但愿转移到分布式环境。没有问题:她们可以转而使用Macromedia JRun Professional,该服务器支持分布式应用。同样,她们servelt和jsp没有任何某些需要重写。如果项目变得极为庞大,错综复杂,她们或许但愿使用Enterprise JavaBeans来封装她们商业逻辑。因而,她们可以切换到BEA WebLogic或Oracle9i AS。同样,不需要对servlet和jsp做出更改。
14、最后,如果她们项目变得更庞大,她们或许将她从Linux转移到运营IBM WebSphereIBM大型机上。她们还是不需要做出任何更改。6、安全老式CGI程序中重要漏洞来源之一就是,CGI程序经常由通过操作系统外壳来执行。因而,CGI程序必要仔细地过滤掉那些也许被外壳特殊解决字符,如反引导和分号。实现这项防止办法难度也许超过咱们想象,在广泛应用CGI库中,不断发现由此类问题引起弱点。问题第二个来源是,某些CGI程序用不自动检查数组和字符串边界语言编写而成。例如,在C和C中,可以分派一种100个元素数组,然后向第999个“元素“写入数据事实上是程序内存随机某些,这完全合法。因而,如果程序员忘掉执行
15、这项检查,就会将系统暴露在蓄意或偶尔缓冲区溢出袭击之下。Servelt不存在这些问题。虽然servelt执行系统调用激活本地操作系统上程序,它也不会用到外壳来完毕这项任务。固然,数组边界检查以及其她内存包括特性是java编程语言核心某些。7、主流虽然存在许多较好技术,但是,如果提供商助支持她们,或开发人员不懂得如何使用这些技术,那么它们长处又如何体现呢?servelt和jsp技术得到服务器提供商广泛支持,涉及Apache,Oracle,IBM,Sybase,BEA,Maromedia,Causho,Sun/iPlanet,New Atlanta,ATG,Fujitsu,Lutris,Silve
16、rstream,World Wide Web Consortinrm ,以及其她服务器。存在几种低廉插件,通过应用这些插件,Microsoft IIS和Zeus也同样支持servlet和jsp技术,它们运营在Windows,Unix/Linus,MacOS,VMS,和IBM大型机操作系统之上。它们用在航空业、电子商务、在线银行、web搜索引擎、门户、大型金融网站、以及成百上千您寻常光顾其她网站。固然,仅仅是流行并不能证明技术优越性。诸多泛美例子。但咱们立场是:服务器端Java本非一项新、为经证明技术。An Overview of Servlet and JSP TechnologyNagle
17、and WiegleyAbstract:Servlet program running in the server-side,dynamically generated Web page with the traditional CGI and many other similar compared to CGI technology,Java Servlet with a more efficient,easier to use,more powerful and has better portability,more savings to invest .Key words:JSP Tec
18、hnology,Servlet,HTTP server1.1 A Servlets JobServlets are Java programs that run on Web or application servers,acting as a middle layer between requests coming from Web browsers or other HTTP clients and databases or applications on the HTTP server. Their job is to perform the following tasks,as ill
19、ustrated in Figure 1-1.Figure 1-11Read the explicit data sent by the client.The end user normally enters this data in an HTML form on a Web page. However,the data could also come from an applet or a custom HTTP client program.2Read the implicit HTTP request data sent by the browser.Figure 1-1 shows
20、a single arrow going from the client to the Web server (the layer where servlets and JSP execute),but there are really two varieties of data:the explicit data that the end user enters in a form and the behind-the-scenes HTTP information. Both varieties are critical. The HTTP information includes coo
21、kies,information about media types and compression schemes the browser understands,and so on.3Generate the results.This process may require talking to a database,executing an RMI or EJB call,invoking a Web service,or computing the response directly. Your real data may be in a relational database. Fi
22、ne. But your database probably doesnt speak HTTP or return results in HTML,so the Web browser cant talk directly to the database. Even if it could,for security reasons,you probably would not want it to. The same argument applies to most other applications.You need the Web middle layer to extract the
23、 resultsinside a document.4Send the explicit data (i.e.,the document) to the client.This document can be sent in a variety of formats,including text (HTML or XML),binary (GIF images),or even a compressed format like gzip that is layered on top of some other underlying format. But,HTML is by far the
24、most common format,so an important servlet/JSP task is to wrap the results inside of HTML.5Send the implicit HTTP response data.Figure 1-1 shows a single arrow going from the Web middle layer (the servlet or JSP page) to the client. But,there are really two varieties of data sent:the document itself
25、 and the behind-the-scenes HTTP information. Again,both varieties are critical to effective development. Sending HTTP response data involves telling the browser or other client what type of document is being returned (e.g.,HTML),setting cookies and caching parameters,and other such tasks. 1.2 Why Bu
26、ild Web Pages Dynamically?many client requests can be satisfied by prebuilt documents,and the server would handle these requests without invoking servlets. In many cases,however,a static result is not sufficient,and a page needs to be generated for each request. There are a number of reasons why Web
27、 pages need to be built on-the-fly:1 The Web page is based on data sent by the client.For instance,the results page from search engines and order-confirmation pages at online stores are specific to particular user requests. You dont know what to display until you read the data that the user submits.
28、 Just remember that the user submits two kinds of data:explicit (i.e.,HTML form data) and implicit (i.e.,HTTP request headers). Either kind of input can be used to build the output page. In particular,it is quite common to build a user-specific page based on a cookie value.2The Web page is derived f
29、rom data that changes frequently.If the page changes for every request,then you certainly need to build the response at request time. If it changes only periodically,however,you could do it two ways:you could periodically build a new Web page on the server (independently of client requests),or you c
30、ould wait and only build the page when the user requests it. The right approach depends on the situation,but sometimes it is more convenient to do the latter:wait for the user request. For example,a weather report or news headlines site might build the pages dynamically,perhaps returning a previousl
31、y built page if that page is still up to date.3The Web page uses information from corporate databases or other server-side sources.If the information is in a database,you need server-side processing even if the client is using dynamic Web content such as an applet. Imagine using an applet by itself
32、for a search engine site:Downloading 50 terabyte applet,please wait! Obviously,that is silly;you need to talk to the database. Going from the client to the Web tier to the database (a three-tier approach) instead of from an applet directly to a database (a two-tier approach) provides increased flexi
33、bility and security with little or no performance penalty. After all,the database call is usually the rate-limiting step,so going through the Web server does not slow things down. In fact,a three-tier approach is often faster because the middle tier can perform caching and connection pooling.In prin
34、ciple,servlets are not restricted to Web or application servers that handle HTTP requests but can be used for other types of servers as well. For example,servlets could be embedded in FTP or mail servers to extend their functionality. And,a servlet API for SIP (Session Initiation Protocol) servers w
35、as recently standardized (see ). In practice,however,this use of servlets has not caught on,and well only be discussing HTTP servlets.1.3 The Advantages of Servlets Over Traditional CGIJava servlets are more efficient,easier to use,more powerful,more portable,safer,and cheaper than traditional CGI a
36、nd many alternative CGI-like technologies.1EfficientWith traditional CGI,a new process is started for each HTTP request. If the CGI program itself is relatively short,the overhead of starting the process can dominate the execution time. With servlets,the Java virtual machine stays running and handle
37、s each request with a lightweight Java thread,not a heavyweight operating system process. Similarly,in traditional CGI,if there are N requests to the same CGI program,the code for the CGI program is loaded into memory N times. With servlets,however,there would be N threads,but only a single copy of
38、the servlet class would be loaded. This approach reduces server memory requirements and saves time by instantiating fewer objects. Finally,when a CGI program finishes handling a request,the program terminates. This approach makes it difficult to cache computations,keep database connections open,and
39、perform other optimizations that rely on persistent data. Servlets,however,remain in memory even after they complete a response,so it is straightforward to store arbitrarily complex data between client requests.2ConvenientServlets have an extensive infrastructure for automatically parsing and decodi
40、ng HTML form data,reading and setting HTTP headers,handling cookies,tracking sessions,and many other such high-level utilities. In CGI,you have to do much of this yourself. Besides,if you already know the Java programming language,why learn Perl too?Youre already convinced that Java technology makes
41、 for more reliable and reusable code than does Visual Basic,VBScript,or C+. Why go back to those languages for server-side programming?3PowerfulServlets support several capabilities that are difficult or impossible to accomplish with regular CGI. Servlets can talk directly to the Web server,whereas
42、regular CGI programs cannot,at least not without using a server-specific API. Communicating with the Web server makes it easier to translate relative URLs into concrete path names,for instance. Multiple servlets can also share data,making it easy to implement database connection pooling and similar
43、resource-sharing optimizations. Servlets can also maintain information from request to request,simplifying techniques like session tracking and caching of previous computations.4PortableServlets are written in the Java programming language and follow a standard API. Servlets are supported directly o
44、r by a plugin on virtually every major Web server. Consequently,servlets written for,say,Macromedia JRun can run virtually unchanged on Apache Tomcat,Microsoft Internet Information Server (with a separate plugin),IBM WebSphere,iPlanet Enterprise Server,Oracle9i AS,or StarNine WebStar. They are part
45、of the Java 2 Platform,Enterprise Edition (J2EE;see ),so industry support for servlets is becoming even more pervasive.5InexpensiveA number of free or very inexpensive Web servers are good for development use or deployment of low- or medium-volume Web sites. Thus,with servlets and JSP you can start
46、with a free or inexpensive server and migrate to more expensive servers with high-performance capabilities or advanced administration utilities only after your project meets initial success. This is in contrast to many of the other CGI alternatives,which require a significant initial investment for
47、the purchase of a proprietary package.Price and portability are somewhat connected. For example,Marty tries to keep track of the countries of readers that send him questions by email. India was near the top of the list,probably #2 behind the U.S. Marty also taught one of his JSP and servlet training
48、 courses (see ) in Manila,and there was great interest in servlet and JSP technology there.Now,why are India and the Philippines both so interested?We surmise that the answer is twofold. First,both countries have large pools of well-educated software developers. Second,both countries have (or had,at that time) highly unfavorable currency excha