Tomcat installation and the use of detailed explanations

Source: Internet
Author: User
Tags small web server java web port number tomcat server
1. Javaweb ConceptJava Web, is the use of Java technology to solve the relevant web-related technologies in the domain name. The web includes two parts: the Web server and the Web client.
Java applets were used in the earliest web client applications, but this technology was eliminated long ago. Java is very rich in server-side applications,
such as servlet,jsp and third-party frameworks, etc. Java technology has injected powerful impetus into the development of web domain.

Simply put, the Java language is used to implement the program content that the browser can access. Called the Java Web.

Javaweb development is based on request and response:
Request: The browser (client) sends information to the server
Response: Server loopback information to (client) browser

The request and response appear in pairs.



2, Web resource classification: the so-called Web resources are placed on the Internet for external access to the files or programs, and according to their performance and principle of different, divided them into static resources and dynamic resources.

Static Web resources: Fixed immutable data files (static Web page HTML, CSS files, text, audio, video)
Static Web technology: Html+css+javascript

Dynamic Web resources: A service program that runs after the generated data file

Dynamic Web technologies: servlet,jsp,php,. NET, Ruby, Python, and more


3. Common Web servers

Introduction to Web server: Tomcat: A Web server provided by the Apache organization that provides support for JSPs and Servlets. It is a lightweight javaweb container (server) and is currently the most widely used Javaweb server (free).
Jboss: is an open source, Java-compliant EJB server that adheres to the Java EE specification, which supports all Java EE specifications (free).
GlassFish: A javaweb server, developed by Oracle, is a robust business Server that achieves product-level quality (rarely applied and charged).
Resin: is a Caucho company's products, is a very popular application server, servlet and JSP provide good support, performance is relatively good, Resin own Java language development (fees, applications more).
WebLogic: Is the Oracle Company's products, is currently the most widely used Web server, support Java EE specification, and constantly improve to adapt to the new development requirements, suitable for large-scale projects (fees, not much, suitable for large companies).


3.1. Tomcat Server

Open source Small Web server, completely free, primarily for small to medium Web projects, support only a small number of Java EE specifications (that is, Javaweb programming interface), such as Servlets and JSPs



3.2. The relationship between the Tomcat server and the servlet version Servlet:sun The technology provided by the company to develop dynamic Web resources.
JSP: (Java Server Page), a Java-provided technology for developing Web pages.

Tomcat software: Developed by Java. Java software requires a JDK when it runs.



Backward compatible TOMCAT7 also supports the servlet3.0/jsp2.2 specification, which can support javaee6.0 current Enterprise common version 6.*/7.*/8.*

3.3. Tomcat download and installation instructions to http://tomcat.apache.org download

1) Tomcat Home


2) Tomcat download

3) after downloading the package

4) Install: Unzip


5) The installation directory of Tomcat is introduced:
Bin: The file can be executed.
Conf:tomcat configuration file for server
Lib:tomcat the jar package to be dependent upon startup
Logs:tomcat post-work log files
WebApps: Is the directory of the Tomcat project.

After the work:jsp file has been translated, it is stored in the current directory, where the session object is stored after it is serialized.


3.4. Tomcat Server Startup (* * Focus)
Precautions:
1, Java_home: Environment variables. and configure the directory to the JDK, the complete process is as follows:


Open the console (CMD command opens the window). Input java-version Test


2. Start the Tomcat directory. The Tomcat directory/bin/startup.bat (window boot file) found Startup.bat double-click Run. There will be a black window, black windows do not close. (if off, it's equivalent to stopping Tomcat.) )


3, enter in the browser address bar: http://localhost:8080 or http://127.0.0.1:8080localhost, if you see the following page, to prove the success of the start


3.5. Configure the port for TOMCAT (* * * * emphasis)


Tomcat default port is 8080 (Access port)
The default port for HTTP is 80 if the input http://www.baidu.com is equivalent to http://www.baidu.com:80 when accessed. When the project is actually on-line, usually using 80, modify the method as follows:
1) Find the Tomcat directory/conf/server.xml
2) Modify the value of port to change the port value to 80
3) then enter the HTTP://127.0.0.1:80 or http://127.0.0.1 access test in the browser

Access success ...


3.6. Catalina run to start Tomcat Tomcat boot, there is also a way to start is on the command line, the first to switch your current directory to your Tomcat directory \ Bin directory, the following is my location



Then execute Catalina Run this command to start Tomcat. What is the benefit of this command? When Tomcat fails to start, there will be a flash of the situation,

When we use the Catalina Run command to start Tomcat, we can clearly see why Tomcat failed, even if there were any errors. Will not flash past.


3.7. There are three ways to disable Tomcat .
First: Ctrl + C to close the Tomcat server
Second: Click the Close button in the upper right corner of the Tomcat window (Violent stop server)
Third: Locate the Tomcat directory/bin/shutdown.bat file and double-click Execute to close Tomcat.

4. Two methods commonly used in the deployment of projects to Tomcat

Html,servlet The information we wrote about, deploying it to Tomcat.


4.1. The first method: in the Tomcat directory/conf/server.xml configuration---Understand the configuration in the host element of the Conf/server.xml file, for example:
Write the following within the host tag
<context path= "/atguigu" docbase= "D:\atguigu"/>
<context path= "browser to access directory---virtual directory" docbase= "the disk directory where the site is located"/>

After the configuration is done, restart the server.

Disadvantage (after Tomcat7.0): If configuration error: Tomcat will fail to start. (If other sites are stored in Tomcat), other sites will be down.


4.2, the second way: Copy the site directory to the Tomcat/webapps directory (commonly used, must master) has a Web site (a folder), the folder is copied to the Tomcat WebApps directory.

The name of the folder is the directory where the site or project is accessed. Equivalent to configuring <context path= "" Previously


4.3, the Site Directory compressed into a war package deployed to the Tomcat War package: is a compressed file zip format of the compressed file. Except that the extension is not a. zip but a. War

Zip Our project, change it to war, copy the war file to the Tomcat/webapps directory
Step 1, compress the contents of the folder into a zip format, click on a folder to deploy, select all and then compress
Step 2, modify the file suffix named. War
Step 3. Copy the war file to the WebApps directory. Tomcat will extract the war files by itself.


4.4, WebApps directory under the/root Project Access When we enter the HTTP://IP address directly in the browser: port number so the default access is the Tomcat directory/webapps/root directory
If the WebApps has a root project below. Then at the time of the visit, you can simply omit the name of the project to find the root directory


5. Integrate Tomcat and Eclipse development tools (* * * common must master)


5.1. Open the Server View window for Eclipse


In the first case, open the Servers window directly in the second case, the Search Servers window opens
Figure one, open the total Eclipse View Diagram II: Enter Server filter out Server window Option Servers Server window has opened successfully, as shown below:
5.2. Create a Tomcat server


1) In the Servers window, click the Create server text prompt to connect. The following figure: 2) Create a new Tomcat server instance

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.