使用Servlet前Tomcat介绍

虚拟目录的映射方式:让tomcat服务器自动映射
tomcat服务器会自动管理webapps目录下的所有web应用,并把它映射成虚似目录。换句话说,tomcat服务器webapps目录中的web应用,外界可以直接访问。
Tomcat服务器的启动是基于一个server.xml文件的。

Tomcat服务器启动端口默认配置

<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />

Tomcat服务器配置url
添加host

<Host name="xxx.xx.xx.xxx"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
 
        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->
 
        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />
</Host>

JavaWeb应用的组成结构

 

 

 

 

 WebRoot Web应用所在目录,一般情况下虚拟目录要配置到此文件夹当中。

    WEB-INF此文件夹必须位于WebRoot文件夹里面,而且必须以这样的形式去命名,字母都要大写。

      web.xml配置文件,有格式要求,此文件必须以这样的形式去命名,并且必须放置到WEB-INF文件夹中。

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                      http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
  version="4.0"
  metadata-complete="true">
 
  <display-name>Welcome to Tomcat</display-name>
  <description>
     Welcome to Tomcat
  </description>
 
</web-app>

 

 

posted @ 2020-07-07 22:30  熊熊会发光哦  阅读(106)  评论(0编辑  收藏  举报