Tomcat指南(一)前言

Tomcat has eased the lives of thousands of Java™ developers, supplying them with a free environment for testing and deploying web applications. Tomcat has proved its mettle in all kinds of environments, providing the foundation you’ll need to apply your Java expertise to the Web.Tomcat缓解了数千名Java™开发人员的生活,为他们提供了一个测试和部署web应用程序的免费环境。Tomcat已经在各种环境中证明了它的能力,为您将Java专业知识应用于Web提供了所需的基础。

Tomcat is a Java servlet container and web server from the Apache Software Founda- tion (http://tomcat.apache.org). A web server is, of course, a program that dishes out web pages in response to requests from, for example, a user sitting at a web browser. But web servers aren’t limited to serving up static HTML pages; they can also run programs in response to user requests and return the dynamic results to the user’s browser. This is an aspect of the Web that Apache’s Tomcat is very good at because Tomcat provides both Java servlet and JavaServer Pages (JSPs) technologies (in addi- tion to serving traditional static pages and external CGI programs written in any pro- gramming language). The result is that Tomcat is a good choice for use as a web server for many applications, including using it as a high performance production web server. And it’s a very good choice if you want a free, open source (http:// opensource.org) servlet and JSP engine. It can be used standalone and in conjunction with other web servers such as Apache httpd.Tomcat是Apache软件基金会的Java servlet容器和web服务器(http://tomcat.apache.org). 当然,网络服务器是一个程序,它根据例如坐在网络浏览器前的用户的请求输出网页。但网络服务器并不局限于提供静态HTML页面;它们还可以根据用户请求运行程序,并将动态结果返回给用户的浏览器。这是Apache的Tomcat非常擅长的Web方面,因为Tomcat提供了Java servlet和JavaServer Pages(JSP)技术(除了提供传统的静态页面和用任何编程语言编写的外部CGI程序)。结果是,Tomcat是许多应用程序用作web服务器的好选择,包括将其用作高性能生产web服务器。如果你想要一个免费的开源(http://opensource.org)servlet和JSP引擎,这是一个非常好的选择。它可以独立使用,也可以与Apache httpd等其他web服务器结合使用。

Can’t you just download and run Tomcat from the Apache Software Foundation’s web site? Well, of course you can, and you’ll need to, but there is a lot more to Tom- cat than just getting it running. You’ll get more out of Tomcat if you understand how and why it was written. So in Chapter 1, Getting Started with Tomcat, we explain that. You will then be better able to make informed decisions on choices you might need to make when installing Tomcat, so we spend the rest of the chapter on the installation and startup procedures.你不能从Apache软件基金会的网站下载并运行Tomcat吗?当然,你可以,而且你需要,但Tomcat还有很多事情要做,而不仅仅是让它跑起来。如果您了解Tomcat的编写方式和原因,您将从中获得更多。因此,在第1章“Tomcat入门”中,我们对此进行了解释。然后,您将能够更好地就安装Tomcat时可能需要做出的选择做出明智的决定,因此我们将在本章的其余部分介绍安装和启动过程。

In Chapter 2, Configuring Tomcat, we show you all about configuring Tomcat. We talk about when you should use Tomcat as a standalone web server and servlet container and when it’s best to use Tomcat with the Apache httpd web server. Then, we show you how to configure realms, roles, users, servlet sessions, and JNDI resources, includ-

ing JDBC DataSources. Next, we show how to turn on and off the auto-reloading of

servlets, how to relocate the webapps directory, and how to map user home directories

for access through Tomcat. Then, we go over how to enable and disable the example web applications and how to enable common gateway interface scripting in Tomcat. And finally, we close out the chapter by introducing you to the Tomcat administration web application, which allows you to configure Tomcat through your web browser.在第2章“配置Tomcat”中,我们将向您展示有关配置Tomcat的所有内容。我们讨论了何时应该将Tomcat用作独立的web服务器和servlet容器,以及何时最好将Tomcat与Apache httpd web服务器一起使用。然后,我们将向您展示如何配置领域、角色、用户、servlet会话和JNDI资源,包括-JDBC数据源。接下来,我们将展示如何打开和关闭自动重新加载servlet、如何重新定位webapps目录以及如何映射用户主目录通过Tomcat访问。然后,我们将介绍如何启用和禁用示例web应用程序,以及如何在Tomcat中启用通用网关接口脚本。最后,我们通过向您介绍Tomcat管理web应用程序来结束本章,该应用程序允许您通过web浏览器配置Tomcat。

With Tomcat installed and configured just the way you like it, you’re ready to learn more about servlet and JSP web applications and how to deploy them into your Tomcat. In Chapter 3, Deploying Servlet and JSP Web Applications in Tomcat, we show you the layout of a web application, how to deploy a web application, and how to deploy individual servlets and JSP pages. Next, we show you how to build web application archive files and how to deploy them. To make things less tedious, we review how to automate the deployments of your web applications by copying, using the built-in manager web application, and using the Jakarta Ant build tool.按照您喜欢的方式安装和配置Tomcat后,您就可以了解更多关于servlet和JSP web应用程序以及如何将它们部署到Tomcat中了。在第3章“在Tomcat中部署Servlet和JSP Web应用程序”中,我们将向您展示Web应用程序的布局、如何部署Web应用程序以及如何部署单个Servlet和JSP页面。接下来,我们将向您展示如何构建web应用程序归档文件以及如何部署它们。为了使事情不那么乏味,我们回顾了如何通过复制、使用内置的管理器web应用程序和使用Jakarta Ant构建工具来自动化web应用程序的部署。

Once you have Tomcat serving your web application, you may want to do some per- formance tuning. In Chapter 4, Tomcat Performance Tuning, we show you how to measure and improve your Tomcat’s performance. We go over adjusting the num-

ber of processor Threads, JVM and OS performance issues as they relate to Tomcat,

turning off DNS lookups, and how to speed up JSPs. We round out the chapter by

discussing how capacity planning can affect performance.一旦让Tomcat为web应用程序提供服务,您可能需要进行一些性能调优。在第4章“Tomcat性能调优”中,我们将向您展示如何测量和改进Tomcat的性能。我们反复调整数字-处理器线程、JVM和操作系统性能问题,关闭DNS查找以及如何加速JSP。我们以以下方式完成了这一章讨论容量规划如何影响性能。

Tomcat works as a complete standalone web server. It supports static web pages, external CGI scripts, and many of the other paraphernalia associated with a web site. However, Tomcat’s forte, its raison d’etre, is to be the best servlet and JSP engine on the block. These are the things it does best. If you already run Apache’s httpd web server and don’t want to change everything all at once, Chapter 5, Integration with the Apache Web Server, covers the use of Tomcat with Apache httpd and talks about the several ways of making Tomcat thrive “in front of” or “behind” an Apache httpd installation.Tomcat作为一个完整的独立web服务器工作。它支持静态网页、外部CGI脚本以及与网站相关的许多其他工具。然而,Tomcat的长处,它存在的理由,是成为块上最好的servlet和JSP引擎。这些是它最擅长的事情。如果您已经运行了Apache的httpd web服务器,并且不想一次更改所有内容,那么第5章“与Apache web服务器的集成”将介绍Tomcat与Apache httpd的使用,并讨论了使Tomcat在Apache httpd安装“前面”或“后面”茁壮成长的几种方法。

Whether you’re providing e-commerce, putting up a mailing list, or running a per- sonal site, when you’re connected to the Internet, your site is exposed to a lot of peo- ple, including a few weirdos who think it’s OK to exploit the vulnerabilities in your server software for fun and/or profit. Because security is important, we devote Chapter 6, Tomcat Security, to the topic of how to keep the online thugs at bay.无论你是提供电子商务、发布邮件列表还是运营个人网站,当你连接到互联网时,你的网站都会暴露给很多人,包括一些认为利用服务器软件中的漏洞来取乐和/或获利是可以的怪人。由于安全性很重要,我们将在第6章“Tomcat安全性”中专门讨论如何阻止在线暴徒。

In Chapter 7, Configuration, we talk about the Tomcat configuration files, server.xml and web.xml, as well as tomcat-users.xmlcatalina.policycatalina.properties, and con- text.xml files. Each can be modified to control how Tomcat works.在第7章“配置”中,我们讨论了Tomcat配置文件、server.xml和web.xml,以及Tomcat-users.xml、catalina.policy、catalina.properties和con-text.xml文件。每个都可以修改以控制Tomcat的工作方式。

When something goes wrong with your Tomcat or a web application, Chapter 8, Debugging and Troubleshooting, shows you some ways to diagnose the problem. We show you what to look for in the logfiles, how the web browser interacts with Tom- cat’s web server during a request, how to get verbose information about a particular request, and what to do if Tomcat just won’t shut down when you tell it to.当您的Tomcat或web应用程序出现问题时,第8章“调试和故障排除”将向您展示一些诊断问题的方法。我们向您展示了在日志文件中查找什么,web浏览器在请求期间如何与Tom-cat的web服务器交互,如何获取特定请求的详细信息,以及如果Tomcat在您告诉它关闭时不关闭该怎么办。

Not everyone wants to run a prebuilt binary release of Tomcat, so in Chapter 9, Building Tomcat from Source, we show you how to compile your own Tomcat. We show you step-by-step how to install the Apache Ant build tool, download all neces- sary support libraries, and build your Tomcat.并非所有人都希望运行Tomcat的预构建二进制版本,因此在第9章“从源代码构建Tomcat”中,我们将向您展示如何编译自己的Tomcat。我们将逐步向您展示如何安装Apache Ant构建工具,下载所有必要的支持库,并构建您的Tomcat。

If you’ve got more request traffic than a single Tomcat can handle, or if you want your site to keep serving requests even if one of your servers crashes, your site may need to run on more than one Tomcat server, or more than one Apache, or a combi- nation of the two. Sometimes the only solution is more hardware. In Chapter 10, Tomcat Clustering, we show you some options for running two or more Tomcat serv- let containers in parallel for both fault tolerance and higher scalability, and we dis- cuss the pros and cons of various clustering approaches.如果您的请求流量超过了单个Tomcat的处理能力,或者即使您的一台服务器崩溃,您也希望您的网站继续提供请求,那么您的网站可能需要在多台Tomcat服务器、多台Apache或两者的组合上运行。有时,唯一的解决方案是增加硬件。在第10章“Tomcat集群”中,我们向您展示了并行运行两个或多个Tomcat serv-let容器以实现容错性和更高可扩展性的一些选项,并讨论了各种集群方法的优缺点。

In Chapter 11, Final Words, we give an overview of the Tomcat open source project’s community resources, including docs, mailing lists, other web sites, and more. These are valuable resources for solving any problems you may have with future versions of Tomcat, and they can also help you get more involved in the development of Tom- cat if that is one of your goals.在第11章“最后的话”中,我们概述了Tomcat开源项目的社区资源,包括文档、邮件列表、其他网站等。这些是解决您在未来版本的Tomcat中可能遇到的任何问题的宝贵资源,如果这是您的目标之一,它们还可以帮助您更多地参与Tom-cat的开发。

Depending on your operating system, installing Java may not be as straightforward as you think. To ensure that Tomcat runs well on your server computer, in Appendix A, Installing Java, we show you step-by-step how to install a Java runtime, and explain some Java issues to watch out for.根据您的操作系统,安装Java可能并不像您想象的那么简单。为了确保Tomcat在您的服务器计算机上运行良好,在附录A“安装Java”中,我们将逐步向您展示如何安装Java运行时,并解释一些需要注意的Java问题。

  • 23
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值