Article Directory
Server overview
Hardware server
oracle server (one unit worth millions of dollars)
- Starting with 32G of memory, generally 128G
- To learn and use, you can directly use the notebook as a hardware server (simulated hardware server: local computer)
Software server
Specifically: web application server, which is an application that can provide browser access
- Common categories of web application servers:
- WebLogic: charges, currently the most widely used server
- The server itself is very large, dozens of G
- Generally used in large-scale projects: Jingdong, Taobao
- WebSphere: Charges
- The server is very large, dozens of G
- Tomcat: Free
- The size is very small, the installation program is only a dozen M
- Tomcat is the most widely used web server in small and medium-sized enterprises/learning
- WebLogic: charges, currently the most widely used server
Tomcat
- Operating environment:
- Need the support of Java-jdk, you must install jdk first
- Environment variables must be configured JAVA_HOME
- Correspondence with Java version
- Tomcat6:jdk5.0
- Tomcat7:jdk6.0
- Tomcat8:jdk7.0
- Tomcat9: the latest version, not recommended
- Tomcat7 startup: in a flash
- JAVA_HOME is not configured
- It has been started, it will not be able to be started when restarted/other programs occupy port 8080
- Solve the problem of not being able to start:
- cmd: netstat -ano, check the PID of the process occupying port 8080, and end him
- Change the Tomcat port number to something else, for example: 8090 (conf/server.xml–connector port), restart Tomcat after modification
- Tomcat's 80 port is a default port: when accessing Tomcat, you can directly enter localhost to access
- Tomcat directory structure
- \bin stores the executable file for starting and shutting down Tomcat
- \conf stores Tomcat configuration files
- \lib stores the dependent jar packages
- \logs store log files
- \temp stores temporary files
- \webapps store web applications (website code written by developers)
- \work stores the JSP converted Servlet file (the real directory where Tomcat runs)
- For example: .java files are run by Tomcat, and .class files are stored in the \work folder
basic concepts
- Itself is a web application
- tomcat is a servlet container
- A Servlet container is a web container, and a web container is not necessarily a Servlet container.
3 ways to deploy web applications
Method 1: Restart the server to change
Create a web application: create a folder news1
- news1: This folder is a web application
- 1.html
- 1.css
- 1.js
- WEB-INF folder
- classes: compiled Java code (.class)
- lib: store the jar packages needed by the project
- web.xml: the core configuration file
-
deploy:
-
Add configuration in Tomcat/conf/server.xml
In this way, do not write Chinese comments in the configuration file
<Context docBase="D:\software\news1" path="/aaa"/>
docBase
: Real pathpath
: The virtual path of the browser's visit
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> <Context docBase="D:\software\news1" path="/aaa"/>
-
Under the project path
/WEB-INF/web.xml
in the configuration<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> </web-app>
-
-
access:
- Restart the Tomcat server
- Enter in the address bar of the browser:
localhost:8080/aaa/1.html
----/aaa is the virtual path of the configured website access
Method 2: Deploy directly without restarting
- Create a web application: create a folder news2
- news2: This folder is a web application
- 1.html
- 1.css
- 1.js
- WEB-INF folder
- classes: compiled Java code (.class)
- lib: store the jar packages needed by the project
- web.xml: the core configuration file
-
deploy
-
web.xml
Still need to write under the web application directory -
In the directory
tomcat7\conf\Catalina\localhost
, create anews2.xml
- Tomcat will treat
news2.xml
the file name prefix as the virtual path of the current web application (localhost:8080/news2/1.html)
- Tomcat will treat
-
Edit the
news2.xml
file and add the actual path of the project<Context docBase="D:\software\news2" />
-
-
Configure the default ROOT.xml file
- To
news2.xml
renameROOT.xml
- Write directly in the address bar of the browser:
localhost/1.html
you can access - priority:
- Configured by yourself
ROOT.xml
---->Tomcatwabapps/ROOT/WEN-INF/ROOT.xml
- Configured by yourself
- To
-
access:
- Non-default ROOT.xml:
localhost:8080/news2/1.html
- Default ROOT.xml:
localhost:8080/1.html
- Non-default ROOT.xml:
Method 3: Automatic management
tomcat will automatically manage every web application in webapps
-
deploy:
-
Copy the web application to the
tomcat/conf/webapps/
next -
Default mode
- Change the project name under webaspps to ROOT directly
-
The default default access interface, directly input
localhost
, it will display the content of 1.html-
Add configuration information to the ROOT/WEB-INF/web.xml file
<welcome-file-list> <welcome-file>1.html</welcome-file> </welcome-file-list>
-
-
-
access:
- Non-default:
localhost:8080/news3/1.html
can be accessed through - Default: just by
localhost
visiting
- Non-default:
Configure virtual host
-
In
tomcat7/conf/server.xml
the<Host name="localhost"></Host>
Add Configuration contents<Host></Host>
name: The domain name you want to modify
appBase: the root path of the project (current directory structure D:\software\baidu\news3\ various files)
<Host name="www.baidu.com" appBase="D:\software\baidu"></Host>
-
Modify the local host file
Host path:
C:\Windows\System32\drivers\etc\Host
The domain name access in the browser will be resolved through the DNS domain name resolver. If you do not modify the local localhost, you cannot access your virtual host; you can bypass DNS resolution by configuring the local Host file
127.0.0.1 www.baidu.com
-
test
Browser address bar:
www.baidu.com/news3/1.html
OK
IDEA configure Tomcat
- Run—Configurations—+—Tomcat Server
-
In the above interface, select Deployment—+ sign on the right to add the project's architecture
-
Start Tomcat, you can access the web project through the configured virtual path