Decompress tomcat configuration and use (environment variable setting and testing, a simple web application instance)

Source: Internet
Author: User

Tomcat configuration and testing:

Step 1: Download Tomcat and decompress it to any drive letter

Step 2: configure system environment variables

I am at tomcat5.5, and decompress it to the D Drive (Path: D: \ Program Files \ tomcat5.5 ),

Although we now know that the tomcat5.5 server is under pressure, if we start the Tomcat server at this time, the system does not know where to find the Tomcat server, so I should first give a description to the system, both environment variables are configured.

To start Tomcat, you need two environment variables (note that I am talking about start): java_home (the JDK directory) and catalina_home (the Tomcat directory you are currently using)

The configuration steps here are as follows: My computer> Properties> advanced> Environment Variables

I personally set the environment variables in the user variables, but also in the system variables, as per my personal needs:

Variable Configuration:

Create-> variable name: java_home variable value: D: \ Program Files \ Java \ jdk1.6.0

Create-> variable name: catalina_home variable value: D: \ Program Files \ tomcat5.5

After the configuration is complete, test whether the configuration is successful:

Start Menu-> Run-> cmd (enter the CMD command)-> enter the command window

Enter the set java_home and set catalina_home commands respectively. If yes, the configuration is successful,


Start the Tomcat server:

Step 1: Go to the bin folder in the Tomcat directory and run the following command:

D: (enter the D disk command)

Cd d: \ Program Files \ tomcat5.5 \ bin (to prevent errors, copy and paste them directly)

Startup. BAT (command for starting Tomcat server)

When the Tomcat server is successfully started, "server startup in 5437 MS" is displayed (note that 5437ms is variable)


Command: shutdown. bat

In this case, you can enter http: // localhost: 8080 in the browser. If http: // localhost:/is enabled, the server configuration is successful.

At this point, the configuration and startup of the tomcat5.5 server are complete.

Bytes ---------------------------------------------------------------------------------------------------------------------

The following is a simple web application example:

Step 1: Create a folder for a Web application and configure the Web. xml file

Go to disk D and find the webapps folder under the Tomcat folder (the webapps folder is used to store web applications. This file contains 6 examples by default ),Create a Serv-app folder (name as needed), create a WEB-INF folder in the Serv-app folder (name is fixed and must be capitalized ), create a classes folder in the WEB-INF folder to store. class file) and Web. XML file (used to configure Servlet) And enter the following in the web. xml file:Code:

<? XML version = "1.0" encoding = "UTF-8"?>
<Web-app version = "2.4"
Xmlns = ""
Xmlns: xsi = ""
Xsi: schemalocation = "


Step 2: Test the Web Application

Create a test.html file in the serv-appfile and enter some content (such as Hello) at will. In this case, we need to stop the Tomcat server, according to the shutdown mentioned above. bat command (enter this command in the Command window), because the Tomcat server will detect web applications under the webapps file when running, so, when modifying a web application, it is best to stop the server first. After the modification, start the server.

Start the server now and enter startup in the Command window. bat command (Note that if you open a new command window, you must enter the bin directory under the Tomcat directory, and then enter startup. bat command, you can refer to the figure above to configure the Tomcat server). After the Tomcat server is successfully started, enter http: // localhost: 8080/Serv-APP/test.html If Hello is displayed, the Web application is configured successfully.

Step 3: Write a Java file and generate a. Class File

Create a helloservlet. Java file (with any name) in the classes folder. Enter the following code in the file:

Note that the class name and file name must be consistent.

Package com.tar ENA;

Import java. Io .*;
Import javax. servlet .*;
Import javax. servlet. http .*;
Public class helloservlet extends httpservlet
Public void doget (httpservletrequest request, httpservletresponse response)
Throws ioexception, servletexception {
Response. setcontenttype ("text/html ");
Printwriter out = response. getwriter ();
Out. Print ("My first servlet !!! ");
Out. Close ();

The servlet jar package is used here, so we need to configure it in Environment Change; otherwise, an error will be reported.

My computer-> properties-> advanced-> Environment Variables

New-> variable name: classpath variable value: D: \ Program Files \ tomcat5.5 \ common \ Lib \ servlet-api.jar

After the configuration is successful, for clarity, I open a new command window and run the set classpath command. If the variable value is displayed, the configuration is successful.

Then, enter


Cd d: \ Program Files \ tomcat5.5 \ webapps \ Serv-apps \ WEB-INF \ Classes

Javac *. Java-D. (asterisk, only all java files)

Now, go to the class folder and you will see a helloservlet. Class file under the COM/tarena directory, indicating that the. Java file is successfully compiled into a. Class file.

Step 4: configure the Web. xml file

Enter the following code in the web. xml file:

<Servlet-Name> helloservlet </servlet-Name>
<Servlet-class> com.tar Ena. helloservlet </servlet-class>

<Servlet-Name> helloservlet </servlet-Name>
<URL-pattern>/Hello </url-pattern>

Step 5: test the Web Application

If the Tomcat server is always started at the time of modification, you must first disable it and then start the Tomcat server.

Enter http: // localhost: 8080/Serv-APP/hello in the address bar of the browser. If my first servlet is displayed !!! Indicates that the Web application is successful.

So far, a simple web application has been successfully completed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.