A detailed explanation of Tomcat and Java Web Development technology

Source: Internet
Author: User
Tags zip java web root directory tomcat tomcat server

This chapter describes how to create and publish Web applications on Tomcat. Let's start with the directory structure of Tomcat and the directory structure of Web applications, then explain how to deploy HTML, Servlet, JSP, and tag library to a Web application, and then introduce ways to package and publish the entire Web application. Finally, it describes how to configure a virtual host on Tomcat.

This chapter focuses on the structure and publishing methods of Web applications, so there is no detailed explanation of the servlet and JSP examples in this chapter, and the techniques for servlet and JSP can be referenced separately from the other chapters.

Directory Structure of 2.1 tomcat

Before you publish a Web application on Tomcat, first understand the directory structure of Tomcat. Tomcat directory structure See table 2-1, these directories are subdirectories.

Table 2-1 Tomcat directory structure

directory description
/bin stored on Windows platform and Linux flat On the stage, start and close the Tomcat script file
a variety of configuration files for the Tomcat server, where the most important profile is Server.xml
contains 3 subdirectories: Classes, lib, and WebApps
various jar files required to store Tomcat servers
Two Web applications hosting Tomcat: Admin application and manager apply
jar files that store tomcat servers and all Web applications can access
/shared/lib
/logs store Tomcat's log file
when publishing a Web application, place the Web application file in this directory by default
/work tomcat put the JSP-generated servlet in this directory

As you can see from table 2-1, jar files can be placed in the/server/lib directory,/common/lib, and/shared/lib directories, and the difference is:

Jar files in the/server/lib directory can only be accessed by the Tomcat server

Jar files in the/shared/lib directory can be accessed by all Web applications, but not by the Tomcat server

Jar files in the/common/lib directory can be accessed by Tomcat server and all Web applications

In addition, for the Java Web application that will be described below, in its Web-inf directory, Lib subdirectories can be created, and various jar files are placed in Lib subdirectories, which can only be accessed by the current Web application.

Only jar files are accepted in the Lib directory mentioned above, if the class compressed file is a zip file, it should be expanded, repackaged as a jar file, and then copied into the Lib directory. If you copy the zip file directly to the Lib directory, you will find that the Tomcat server still cannot find the related classes. Package command See section 2.2.8.

2.2 Creating and publishing Web applications

A Java Web application consists of a set of static HTML pages, Servlet, JSP, and other related classes. Each component has a fixed storage directory in the Web application. The configuration information for the Web application is stored in the Web.xml file. When you publish certain components, such as servlet, you must add the appropriate configuration information to the Web.xml file.

Directory structure for 2.2.1 Web applications

Web applications have a fixed directory structure, which assumes the development of a Web application named HelloApp. First, you should create the directory structure for this Web application in the/webapps directory, see table 2-2.

Table 2-2 The directory structure of Web applications

Directory Description
/helloapp The root directory of Web applications, all JSP and HTML files are stored in this directory
/helloapp/web-inf Publish description file for Web application Web.xml
/helloapp/web-inf/classes Store a variety of class files, servlet class files are also placed in this directory
/helloapp/web-inf/lib The various jar files needed to store the Web application

For example, in this directory, you can store the JDBC driver's jar file

Related Article

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: info-contact@alibabacloud.com 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.