Tomcat: Web server software

From the original personal Gitee: "Tomcat: Web Server Software"

Tomcat: web server software

Tomcat is a pure Java language of

installation

Download https://tomcat.apache.org/download-80.cgi

No need to install, just unzip the compressed package.

Note: It is recommended not to have Chinese characters and spaces in the installation directory

Directory Structure

start up

  • Windows: Run./bin/startup.bat

  • Linux: Run./bin/startup.sh

Insert picture description here

Possible problems

Chinese garbled

See the blog post for details [ Chinese garbled characters when Tomcat starts ]

The black window flashed by

  • Reason: JAVA_HOME environment variable is not configured correctly
  • Solution: Configure the JAVA_HOME environment variable correctly

Startup error

violence

  • Find the occupied port number, and find the corresponding process, kill the process
  • cmd>> netstat -anoview process id (PID)> task manager (view-select column-PID)> end process (corresponding to PID)

tender

  • Modify its own port number
  • ./conf/server.xml

  • <Connector port="8888" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8445" />

  • Generally, the default port number of tomcat will be changed to 80. Port 80 is the default port number of the http protocol.

    • Benefit: When accessing, you don’t need to enter the port number
  • This method can realize the coexistence of multiple Tomcats on a single machine

access

Browser input:

  • Visit yourself: http://localhost:8080
  • Visit others: http:// other people's ip:8080

Insert picture description here

View IP address

  • cmd>$ ipconfig>IPv4 address

shut down

  • For the server itself, it is recommended to use **"Normal shutdown"**
  • But in the later stage, Tomcat is used with IDEA

Normal shutdown

  • There are two ways:
  1. Run manually./bin/shutdown.bat
  2. In the Tomcat window, pressCtrl+C

Forced shutdown

  • Click the X in the upper right corner of the Tomcat window

How to deploy/configure the project

  • There are three ways:
  1. Just put the project in the webappsdirectory
  2. Configuration conf/server.xmlfile
  3. In the conf\Catalina\localhostcreation of any name xml file

virtical list

When the browser http://localhost:8080needs to access a certain item through access, it needs to be added after it /目录或路径(called a virtual directory )

Just put the project in the webapps directory

  • /项目(文件夹)名: The access path of the project, also known as the virtual directory

Insert picture description here

Simplify deployment

  • There is also a form of simplified deployment in the first way
  • Mark the project into a war package, and then place the war package in the webapps directory
  • The war package will be automatically decompressed
  • If you delete the project, delete the corresponding war package. The project folder corresponding to the production will be deleted automatically.

automatic decompression of war package

Configure the conf/server.xml file

  • <Host>Configure in the label body
  • <Context docBase="D:\hello" path="/hehe" />
  • docBase : The path where the project is stored
  • path : virtual directory
  • Disadvantages: Need to modify the configuration file, not very safe

Create an xml file of any name in conf\Catalina\localhost

  • Write in file
  • <Context docBase="D:\hello" />
  • Virtual directory: the name of the xml file. such aslocalhost:8080/xml文件/index.html
  • Hot deployment method: After deleting or modifying the file name, there is no need to restart the service.

Type of deployment project

  • Static project
  • Dynamic project

Static project

  • Can only store static resources
  • HTML, CSS, JavaScript, pictures, audio, video, text, etc.

Dynamic project

  • Not only can store static resources, but also dynamic resources

Directory structure (Java dynamic project)

项目根目录
  ﹂-WEB-INF目录
	  ﹂web.xml:web项目的核心配置文件
	  ﹂classes目录:放置字节码文件的目录
	  ﹂lib目录:放置依赖的jar包

such as:

Use Tomcat in IDEA

Integrated into IDEA

Insert picture description here
Insert picture description here
Insert picture description here

New web project

Insert picture description here

Run the project

Insert picture description here

note:

  1. Default war package deployment

  2. /: The default virtual directory is set to the root directory of the current project

Other configuration

  • When redeploying the project, do not restart the Tomcat server

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_43438052/article/details/114656069