用 Tomcat 和 Eclipse开发 Web 应用程序英文原文及中文翻译
时间:2025-05-06
时间:2025-05-06
毕业设计(外文翻译)
Developing Web applications with
Tomcat and Eclipse
Required components
The Eclipse V3.2 Callisto integrated development environment (IDE) includes tools for doing Web development and integrating with servers. So, aside from the software development kit (SDK), you need only Eclipse and Apache Tomcat installed. The versions featured in this article are listed below.
Table 1. Components and versions used
Component Version used in this article
Eclipse Platform 3.2.2
Java EE 5 SDK 1.5.0_09
Apache Tomcat 5.5.20
The Eclipse IDE is an open source IDE used as the development environment for your Java™Server Pages (JSPs) and Java files. With the Web and Java 2 Platform, Enterprise Edition (J2EE) Development tools installed, Eclipse is great tool for creating HTML, JSPs, and servlets.
You need the Java SDK to run servlets on your machine. Finally, Apache Tomcat is an open source Web and servlet container, used in the official reference implementations for Java Servlet and Java Server Pages. Installation
Installation of Eclipse and Tomcat is similar —both are extracted from the archive file format into a folder on your hard disk. If you ever want to uninstall either, it's as simple as deleting the directory in which you extracted the files.
Install Eclipse
1
毕业设计(外文翻译)
2 To install the Eclipse IDE, unpack the compressed (.zip or .tar.gz) file you downloaded from Eclipse, then move the unpacked folder into a convenient location. I try to install it in a location that follows the conventions of whatever operating system I'm using. If I'm installing Eclipse on a Macintosh, I put the Eclipse folder in the Applications folder. If I'm using Microsoft™ Windows™, I put the unpacked folder into the C:\Program Files directory.
Once you've downloaded and installed Eclipse, start it up. Before you can create a Web project, you need to install the J2EE and Web Development plug-ins. Fortunately, it's easy to install the plug-in using the Callisto Discovery Site.
Install the Web tools
With the Eclipse IDE running, select Help > Software Updates > Find and Install. This option lets you download and install the Web tools without going to a Web site.
Select Search for New Features to Install, as shown below, then click
Next.
Figure 1. Install/Update window
Select Callisto Discovery Site, as shown below, then click Next.
毕业设计(外文翻译)
3
Figure 2. Select the Callisto Discovery Site
Under Callisto Discovery Site, check the Web and J2EE Development box. The wizard immediately warns you that you're missing dependencies. Click Select Required, and these warnings should disappear. Some or all of the components in the Graphical Editors and Frameworks and Models and Model Development categories are selected (as shown in Figure 3) because they're
required for the installation of the Web and J2EE plug-ins.
Figure 3. Select features for installation
毕业设计(外文翻译)
Click Next to continue, and license agreements appear for each feature you've selected. If you agree with the licenses, accept them and follow the wizard through the rest of the process. When the IDE is finished installing the plug-ins, it asks you to restart Eclipse in order for the changes to take effect. Be sure you restart the IDE before continuing.
After you restart the IDE, the new features are available to begin developing dynamic Web projects.
Install Tomcat
To install Apache Tomcat, extract the files from the downloaded archive and place them into a directory. I put them in my C:\apps directory to make them easy to locate later. That's it for now; use Eclipse as shown later to start Tomcat.
Create a new Web project
From the Eclipse IDE, select File > New > Project to view the project wizards. Type Web in the Wizards box, and the New Project window filters the wizards to show the ones that match. This is an easy way to locate the wizard you want instead of going through each item.
Choose Dynamic Web Project from the list. You use the Standard Web Project Wizard to make static HTML Web projects. You can technically use Tomcat to run static Web sites, although a Web server such as Apache Web Server may be a better choice for static content. Web servers built specifically for serving up static pages tend to have less overhead and are tuned for that purpose. Target a runtime
Under Target Runtime, you see <None>, as shown in Figure 4, because you haven't created a runtime yet for Apache Tomcat. Click New to open the New Target Runtime Wizard. Select Apache Tomcat V5.5 from the Apache folder, as shown in Figure 5, then click Next.
4
毕业设计(外文翻译)
5
Figure 4. Create a new dynamic Web project
Figure 5. Create a new server runtime
Now you have the opportunity to name your runtime, although the default name Apache Tomcat V5.5 is fine. Click Browse to locate the base folder for your Apache Tomcat configuration (mine is C:\apps\apache-tomcat-5.5.20, as shown in Figure 6). I recommend leaving the IBM® Java Runtime Environment (JRE) version the same as the workbench default JRE, unless you have a specific
毕业设计(外文翻译)
6 reason to change it. Once you've entered a valid directory, click Finish to
create the runtime configuration.
Figure 6. Define the server location
You're asked if you want to switch to the J2EE Perspective. I always answer yes because that perspective includes views like the Servers view, which help to start and stop Tomcat later. You can always open the Servers view by selecting Window > Show View.