1、word完整版)计算机类外文翻译 外文原文 Introducing JSP、JAVA、Tomcat By: Gary H。 Sockut, Balakrishna R。 Iyer Source: Beginning JSP, JSF and Tomcat Introducing JSP and Tomcat Interactivity is what makes the Web really useful. By interacting with a remote server, you can findthe information you need, keep in
2、touch with your friends, or purchase something online. And everytime you type something into a web form, an application “out there” interprets your request and prepares a web page to respond. 1。Installing Java JavaServer Pages (JSP) is a technology that helps you create such dynamically generated
3、pages by converting script files into executable Java modules; JavaServer Faces (JSF) is a package that facilitates interactivity with the page viewers; and Tomcat is an application that can execute your code and act as a web server for your dynamic pages. Everything you need to develop JSP/JSF web
4、 applications is available for free download from the Internet; but to install all the necessary packages and tools and obtain an integrated development environment, you need to proceed with care。 There is nothing more annoying than having to deal with incorrectly installed software。 When something
5、doesn’t work, the problem will always be difficult to find. In this chapter, I’ll introduce you to Java servlets and JSP, and I'll show you how they work together within Tomcat to generate dynamic web pages. But, first of all, I will guide you through the installation of Java and Tomcat: there wou
6、ldn’t be much point in looking at code you can't execute on your PC, would there? You'll have to install more packages as you progress. Do these installations correctly, and you will never need to second guess yourself. In total, you will need at least 300MB of disk space for Java and Tomcat alone
7、and twice as much space to install the Eclipse development environment.To run all the examples contained in this book, I used a PC with a 2.6GHz AMD Athlon 64x2(nothing fancy, nowadays) with 1GB of memory and running Windows Vista SP2。 Before performing any installation, I reformatted the hard disk
8、 and re-installed the OS from the original DVD。 I don’t suggest for a moment that you do the same! I did it for two opposite but equally important reasons: first, I didn’t want existing stuff to interfere with the latest packages needed for web development; second, I didn’t want to rely on anything
9、already installed。 I wanted to be sure to give you the full list of what you need。 2.Installing Tomcat This is the Java web server, which is the servlet container that allows you to run JSP。 If you have already installed an older version of Tomcat, you should remove it before installing a new vers
10、ion. Tomcat listens to three communication ports of your PC (8005, 8009, and 8080)。 Before you install Tomcat, you should check whether some already-installed applications are listening to one or more of those ports. To do so, open a DOS window and type the command netstat /a. It will display a lis
11、t of active connections in tabular form。 The second column of the table will look like this: Local Address 0。0。0。0:135 0。0.0.0:445 0.0。0。0:3306 The port numbers are the numbers after the colon. If you see one or more of the ports Tomcat uses, after installing Tomcat, you will have to change the
12、 ports it listens to.Here’s how to install Tomcat 7 correctly: (1).Go to the URL http://tomcat。apache。org/download—70。cgi. Immediately below the second heading (“Quick Navigation”), you will see four links: KEYS,7.0.26, Browse, and Archives。 (2)。By clicking on 7.0.26, you will be taken toward the
13、 bottom of the same page to a heading with the same version number。 Below the version heading, you will see the subheading “Core”。 Below that, immediately above the next subheading, you will see three links arranged as follows: 32-bit/64-bit Windows Service Installer (pgp, md5). (3).Click on 32—bit
14、/64—bit Windows Service Installer to download the file: apache-tomcat-7。0.26.exe (8。2 MB). (4).Before launching the installer file, you have to check its integrity. To do so, you need a small utility to calculate its checksum. There are several freely available on the Internet. I downl
15、oaded WinMD5Free from http://www。winmd5。com/, and it worked for me, but this doesn’t mean I consider it better than any other similar utility. It just happened to be the first one I saw. The program doesn't require any special installation: just unzip it and launch。 When you open the Tomcat installe
16、r file, you will see a 32-digit hexadecimal number very much like this:8ad7d25179168e74e3754391cdb24679。 (5)。Go back to the page from which you downloaded the Tomcat installer and click on the md5 link (the third one, and second within the parentheses)。 This will open a page containing a single lin
17、e of text, like this: 8ad7d25179168e74e3754391cdb24679 *apache-tomcat-7。0.26。exe If the hex string is identical to that calculated by the checksum utility, you know that the version of Tomcat installer you have downloaded has not been corrupted or modified in any way. (6)。Now that you have verifi
18、ed the correctness of the Tomcat installer, launch it。 (7)。After you’ve agreed to the terms of the license, you will then see the dialog shown in Figure 1—5. Click on the plus sign before the Tomcat item and select “Service” and “Native” as shown in the figure before clicking on the “Next >” butto
19、n。 (8)。I chose to install Tomcat in the directory “C:\Program Files\Apache Software Foundation\Tomcat” instead of the default “Tomcat 7。0". This is because sometimes you might like to point to this directory (normally referred to as %CATALINA_HOME%) from within a program, and one day you might repl
20、ace Tomcat 7。0 with Tomcat 8.0. By calling Tomcat’s home directory “Tomcat" you are “safe" for years to come. You can also decide to leave the default。 In general, by using the defaults, you are likely to encounter fewer problems, because the default settings of any applications are always tested be
21、st! (9).Next, the Tomcat installer will ask you to specify the connector port and UserID plus password for the administrator login。 Leave the port set to 8080, because all the examples in this book refer to port 8080. If you want, you can always change it later to the HTTP standard port (which is 8
22、0). As UserID/Password, you might as well use your Windows user name and password。 It is not critical。 (10)。Lastly, you will need to provide the path of a Java Runtime Environment. This is the path you saw when installing Java (see previous section)。 With the version of Java I installed, the correc
23、t path is C:\Program Files\Java\jre7. 3.What is JSP JSP is a technology that lets you add dynamic content to web pages. In absence of JSP, to update the appearance or the content of plain static HTML pages, you always have to do it by hand。 Even if all you want to do is change a date or a picture,
24、 you must edit the HTML file and type in your modifications. Nobody is going to do it for you, whereas with JSP, you can make the content dependent on many factors, including the time of the day, the information provided by the user, the user’s history of interaction with your web site, and even th
25、e user’s browser type。 This capability is essential to provide online services in which you can tailor each response to the viewer who made the request, depending on the viewer's preferences and requirements。 A crucial aspect of providing meaningful online services is for the system to be able to re
26、member data associated with the service and its users. That's why databases play an essential role in dynamic web pages。 But let’s take it one step at a time。 Sun Microsystems introduced JSP in 1999。 Developers quickly realized that additional tags would be useful, and the JSP Standard Tag Library
27、JSTL) was born。 JSTL is a collection of custom tag libraries that encapsulates the functionality of many JSP standard applications, thereby eliminating repetitions and making the applications more compact. Together with JSTL also came the JSP Expression Language (EL). In 2003, with the introducti
28、on of JSP 2。0, EL was incorporated into the JSP specification, making it available for custom components and template text, not just for JSTL, as was the case in the previous versions. Additionally, JSP 2.0 made it possible to create custom tag files, thereby perfecting the extendibility of the lang
29、uage。 In parallel to the evolution of JSP, several frameworks to develop web applications became available。 In 2004, one of them, JavaServer Faces (JSF), focused on building user interfaces (UIs) and used JSP by default as the underlying scripting language。 It provided an API, JSP custom tag libra
30、ries, and an expression language。 The Java Community Process (JCP), formed in 1998, released in May 2006 the Java Specification Request (JSR) 245 titled Java Server Pages 2.1, which effectively aligned JSP and JSF technologies。 In particular, JSP 2。1 included a Unified EL (UEL) that merged the two
31、 versions of EL defined in JSP 2。0 and JSF 1。2 (itself specified as JSR 252)。 Sun Microsystems includes JSP 2。1 in its Java Platform, Enterprise Edition 5 (Java EE 5), finalized in May 2006 as JSR 244。 The latest version of Java is 7 (specified in JSR 342 and released in July 2011)。 It includes JSP
32、 2。2, Servlets 3.1 (JSR 340), EL 3.0 (JSR 341), and JSF 2.2 (JSR 344)。 Version 8 is expected in mid—2013. At the time of this writing, Java 7 is only available as part of the JSE (Java Standard Edition) platform。 The latest version of Java released in the JEE (Java Enterprise Edition) platform is 6
33、update 32)。 JSP Elements A JSP page is made out of a page template, which consists of HTML code and JSP elements such as scripting elements, directive elements, and action elements。 In the previous chapter, after explaining how to install Java and Tomcat, I introduced you to JSP and explained JSP
34、's role within web applications. In this chapter, I'll describe in detail the first two types of JSP elements. Introduction Scripting elements consist of code delimited by particular sequences of characters。 The scriptlets,which you encountered in the examples in Chapter 1 and delimited by the pa
35、ir <% and %〉, are one of the three possible types of scripting elements。 The other two are declarations and expressions。 All scripting elements are Java fragments capable of manipulating Java objects, invoking their methods and catching Java exceptions。 They can send data to the output, and they ex
36、ecute when the page is requested. In the hello。jsp example of Chapter 1 (Listing 1-4), you saw that request.getHeader(”user—agent") returns a string that describes the client’s web browser, despite the fact that the variable request wasn’t defined anywhere。 It worked because Tomcat defines several
37、implicit objects: application, config, exception, out, pageContext, request, response,and session。 Directive elements are messages to the JSP container (i。e。, Tomcat)。 Their purpose is to provide information on the page itself necessary for its translation。As they have no association with each indi
38、vidual request, directive elements do not output any text to the HTML response. The first line of the hello。jsp example was a directive: 〈%@page language=”java" contentType=”text/html”%> Besides page, the other directives available in JSP pages are include and taglib. Action elements specify act
39、ivities that, like the scripting elements, need to be performed when the page is requested, because their purpose is precisely to encapsulate activities that Tomcat performs when handling an HTTP request from a client. Action elements can use, modify, and/or create objects, and they may affect th
40、e way data is sent to the output. There are more than a dozen standard actions: attribute, body, element, fallback, forward, getProperty, include, param,params, plugin, setProperty, text, and useBean。 For example, the following action element includes in a JSP page the output of another page: 〈jsp
41、include page=”another。jsp”/> In addition to the standard action elements, JSP also provides a mechanism that lets you define custom actions, in which a prefix of your choice replaces the prefix jsp of the standard actions. The tag extension mechanism lets you create libraries of custom actions, wh
42、ich you can then use in all your applications。 Several custom actions became so popular within the programming community that Sun Microsystems (now Oracle) decided to standardize them。 The result is JSTL, the JSP Standard Tag Library。 The Expression Language (EL) is an additional JSP component tha
43、t provides easy access to external objects (i.e., Java beans)。 EL was introduced in JSP 2.0 as an alternative to the scripting elements, but you can also use EL and scripting elements together. I will describe EL in Chapter 4,after explaining the action elements。 In the next sections, I will first
44、go through the scripting elements, because they are easier to understand and you can use them to glue together the rest。 Then, I will describe the implicit objects and the directives. To help you find the correct examples in the software package for this chapter, I divided them in folders named acco
45、rding to the section title and the functionality tested (e。g。,request object – authentication). 介绍JSP、JAVA、Tomcat 作者: Gary H。 Sockut, Balakrishna R。 Iyer 来源: Beginning JSP, JSF and Tomcat 介绍JSP和Tomcat 互动性
46、使网络变得真的很有用。通过与远程服务器进行交互,您可以找到您需要的信息,与你的朋友保持联系,或者网上购买东西.每次你输入到一个web表单,应用“非常态”的解释你的请求和准备一个web页面回应. 1. 安装JAVA JavaServer Pages(JSP)技术,帮助您把创建的动态页面脚本文件转换为可执行Java模块;JavaServer Faces(JSF)是一个包,帮助使用者与创建的页面进行互动;Tomcat是一个应用程序,该应用程序可以执行你的代码和充当web服务器的动态页面. 所有你需要开发JSP / JSF web应用程序可以从因特网上免费下载,但安装所有必需的包和工具和获取一个
47、集成开发环境,您需要进行护理.没有比处理不正确安装的软件更让人讨厌的事了。当某个程序不能运行,问题经常是很难找到的。 在本章中,我将向您介绍Java servlet和JSP中,我将向您展示如何运用Tomcat生成动态网页。但是,首先,我将指导您完成安装的Java和Tomcat:在你的电脑上不会有不能执行的源代码。 你必须安装更多的包作为你的进程.做这些正确安装,你将永远不需要再怀疑你自己。总的来说,您将需要至少300MB的磁盘空间安装Java和Tomcat。同时还需要600MB的空间安装Eclipse开发环境。运行这本书中包含的所有的示例。我用的电脑规格是2.6 GHz AMD Athlo
48、n 64 x2(现在不算好的了)1 GB内存,运行Windows Vista SP2。在执行任何安装之前,我重新格式化硬盘,安装操作系统从最初的DVD。我不建议一会儿你做同样的事情!我这么做是为了两种截然相反但是同样重要的原因:首先,我不希望现有的东西来干扰web开发所需的最新软件包;第二,我不想依赖任何已安装的程序。我想要给你你需要的完整列表。 2. 安装Tomcat 这是Java web服务器,它是servlet容器,允许您运行JSP。如果您已经安装了一个老版本的Tomcat,你应该在安装新版本之前删掉它。 Tomcat听从你电脑中的三个通信端口 (8005、8009和8005)。在
49、Tomcat安装之前,您应该检查是否已安装好的应用程序听的一个或多个这些端口.打开DOS窗口并输入命令netstat/a。它将以表格的形式显示活动连接的列表.表格的第二行入下: 本地地址 0.0.0.0:135 0.0.0。0:445 0.0.0。0:3306 端口号是冒号后面的数字。如果你看到一个或多个端口Tomcat使用,安装Tomcat之后,你将不得不改变它听的端口号。这里是如何正确安装Tomcat7: (1)、进入网页http://tomcat.apache.org/download—70。cgi。在下面第二行,你会看到四个链接:KEYS,7。0。26, Browse, and Archives. (2)、点击7.0。26, 你将被带到与按键版本号相同的下载页面中。您将看到的副标题“核心”。下面,上面马上下一个副标题,您将看到三个链接安排如下:32位/ 64位Windows服务安装程序(pgp,md5)。 (3)、点击下载32位/ 64位Windows apache—tomcat—7.0。26 exe(8.2 MB)文件。 (4)、在启动安装程序文件之前,您必须检查其完整性。要做到这一点,你需要一个小工具来计算其校验和。在互联网上有很多免费的。我从http://






