In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to configure tomcat. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
one。 download
Just download the tomcat server directly to the official website, choose the corresponding version according to your computer system, download the zip package from the window system, and decompress it after download.
Apache Tomcat 9: https://www.jb51.net/softs/537919.html
Apache Tomcat 8: https://www.jb51.net/softs/537911.html
two。 Configuration
After we finished downloading, we tried to start tomcat. There are two ways to start it.
Go directly to the bin directory of the tomcat server and double-click startup.bat
Enter the bin directory through cmd and enter the command startup.bat
But the question that arises at this time is that the server startup program is just a flash, why?
The problem is that without Java's JDK, we need to configure the system variable JAVA_HOME to the environment variable. As we all know, versions of JDK above 1.5 only need to configure the path variable. But if you want to use tomcat on your machine, you must configure JAVA_HOME to point to the location where JDK is installed.
After the configuration, we can open tomcat normally, double-click startup.bat,tomcat to start normally. When the startup is complete, we type: http://localhost:8080, on the browser address bar to get the following interface
Is it possible to deploy applications using tomcat? not yet. We need some other configurations.
2.1 configure environment variables
We need to configure three system environment variables
ATALINA_BASE: points to the location where tomcat is installed
CATALINE_HOME: points to the location where tomcat is installed
Path:%CATALINA_HOME%\ lib;%CATALINA_HOME%\ bin
2.2 configure the service port for tomcat
The default service port for tomcat is 8080. The service port can be changed through the configuration file, or even by modifying the configuration file to allow tomcat to provide services on multiple ports at the same time
The configuration files for tomcat are placed in the conf directory. Open the server.xml file in this directory using an unformatted text editor and navigate to line 68
Among them, port= "8080" is the service port of web application. Change 8080 to any port, and it is recommended to use more than 1024 ports to avoid conflicts with public ports.
If you need to let tomcat run multiple services, you only need to copy the elements in server.xml and modify the corresponding parameters to achieve a tomcat to run multiple services. Of course, services are provided on different ports.
In the development stage of web application, we usually want Tomat to list all the pages under the root directory of Web application, so that it is more convenient to debug JSP pages. By default, tomcat does not do this for security reasons. We can manually open the web.xml file in the conf directory and change the listing parameter on line 110111 to true, in the following form
Listings true
2.3 access to the console
Tomcat has three consoles, the Server Status console, the Manager App console, and the Host Manager console. The Status console is used to monitor the status of the server, while the manager console can deploy and monitor web applications, so the Manager console is usually used.
To log in to the console, we need the user and password. The user and password of the console are controlled through the JAAS of Tomcat.
We need different roles to log in to the Manager console. Refer to the web.xml file in the\ webapps\ manager\ WEB-INF directory to know that logging in to the console may require different roles. For ordinary developers, you usually need to access resources that match / html/* and / status/*, so we can create a manager-gui role.
Tomcat does not configure any users by default. We can open the tomcat-users.xml file in the conf directory, add the user element to add users, and modify it as follows
A manager user has been added to the above configuration file
After successfully logging in, you can see
The Deploy area under the console is used to deploy web applications. Tomcat provides two ways to deploy web applications: one is to deploy the entire path into web applications, and the other is to deploy war files as web applications.
four。 Deploy web applications
The main ways to deploy web applications are as follows
Take advantage of automatic deployment of tomcat
Deploy using the console
Add custom Web deployment files
Modify server.xml file to deploy Web application
4.1 Automated deployment with tomcat
Using the automatic deployment of tomcat is the simplest and most commonly used way, just copy a web application to the webapps of Tomcat, and the system will deploy the application to tomcat.
4.2 deploy using the console
It is also easy to deploy using the console, which can be entered in the console of the web application as follows
After typing, click the Deploy button, and you will see that there is an extra folder called aaa in the webapps directory of Tomcat. The contents of this folder are exactly the same as those under the E:\ webDemo folder. This shows that when deploying applications using the console, it is still using the automatic deployment of tomcat.
4.3 add custom Web deployment files
The operation steps of this method are as follows: create a new Catalina directory under the conf directory, then create a new localhost directory under the Catalina directory, and finally create a new xml file with any name under the localhost directory-this file is the configuration file for deploying the web application, and the primary file name of the file will be used as the virtual path of the web application. For example, add a dd.xml file to the\ conf\ Catalina\ localhost directory with the following contents
This file specifies the absolute path of the web application. Starting tomcat,tomcat again will deploy the webDemo folder under the / path to the web application.
4.4 modify server.xml file to deploy Web application
This method is to modify the server.xml file in the conf directory. Modifying this file may destroy the system files of Tomcat, and it is not recommended.
five。 Configure the data source
Starting from tomcat 5.5, tomcat has a built-in data source implementation of DBCP, which makes it very convenient to configure DBCP data sources.
Tomcat provides two ways to configure data sources, one is a global data source, which can be accessed by all web applications, and the other is a local data source, which can only be accessed by a single data source.
No matter which data source is configured, you need to provide a JDBC driver for a specific database and copy it to the lib path of Tomcat. For example, copy the JDBC driver of MySQL to the lib path
Local data sources do not need to modify the configuration files of the system, only users need to modify their own Web deployment files, which will not cause confusion in the system, and the data sources are encapsulated in a Web application to prevent access by other applications, providing a good encapsulation. For example, modify the dd.xml file. Add a child element Resource to the Context element, and the file content is as follows
Launch tomcat again, and the web application can access the data source through the JNDI name. Below is the JSP page code for testing access to the data source code.
six。 Some points of attention
When you write a jsp file manually, when you save the file, the file encoding is set to utf-8, otherwise the garbled code is displayed.
The deployment configuration file is different from the configuration file of the web application, and should be distinguished.
Thank you for reading! This is the end of this article on "how to configure the use of tomcat". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.