Tomcat知识点

Tomcat详解

一、tomcat目录主要结构

在这里插入图片描述
一、tomcat配置
conf中主要配置文件为server.xml
在这里插入图片描述

<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!-- Note:  A "Server" is not itself a "Container", so you may not
     define subcomponents such as "Valves" at this level.
     Documentation at /docs/config/server.html
 -->
<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <!--APR library loader. Documentation at /docs/apr.html -->
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
  <Service name="Catalina">

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->


    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         HTTP Connector: /docs/config/http.html
         AJP  Connector: /docs/config/ajp.html
         Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
    -->
    <Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->
    <!-- Define an SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2
         This connector uses the NIO implementation. The default
         SSLImplementation will depend on the presence of the APR/native
         library and the useOpenSSL attribute of the
         AprLifecycleListener.
         Either JSSE or OpenSSL style configuration may be used regardless of
         the SSLImplementation selected. JSSE style configuration is used below.
    -->
    <!--
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true">
        <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
        <SSLHostConfig>
            <Certificate certificateKeystoreFile="conf/localhost-rsa.jks"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>
    -->

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <!--
    <Connector protocol="AJP/1.3"
               address="::1"
               port="8009"
               redirectPort="8443" />
    -->

    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <Engine name="Catalina" defaultHost="localhost">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  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>
    </Engine>
  </Service>
</Server>

端口号配置和web项目配置等在此修改。http默认端口号为80,所以建议端口号修改为80。

本机浏览器访问时使用域名的方法:

找到C:\Windows\System32\drivers\etc目录下的hosts文件,编辑
在这里插入图片描述
在这里插入图片描述
现在开启Tomcat时就可以通过域名访问:
在这里插入图片描述

网站是如何进行访问的?

1.输入一个域名,回车
2.检查本机C:\Windows\System32\drivers\etc目录下的hosts配置文件有没有该域名的映射
有:直接返回该IP
没有:在DNS服务器中寻找
(DNS是全世界所有域名的服务器)

发布一个网站的流程

  • 将自己写的网站,放到服务器(Tomcat)中指定的(webapps)下,就可以访问了
  • 网站该有的结构:
--webapps : Tomcat服务器的web目录
	-ROOT
	-wujing :网站的目录名
		-web-inf
			-classes : java程序
			-lib:web :应用所依赖的jar包
			-web-xml ;网站配置文件
		-index.html 默认的网页
		-static
			-css
				-style.css
			-js
			-img
		-...

笔记来自狂神课程

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Tomcat是一个开源的Java Servlet容器,也是Apache软件基金会的一个项目。它实现了Java Servlet和JavaServer Pages(JSP)规范,提供了一个运行Java Web应用程序的环境。 以下是一些关于Tomcat的常见知识点: 1. Tomcat的架构:Tomcat由多个组件组成,包括Catalina、Coyote、Jasper等。Catalina是Tomcat的核心组件,负责处理Servlet和JSP。Coyote是Tomcat的HTTP协议处理组件,用于接收和处理HTTP请求。Jasper负责编译JSP文件。 2. 配置Tomcat:配置文件位于Tomcat安装目录下的conf文件夹中。其中,server.xml文件是主要的配置文件,可以配置监听端口、虚拟主机等。 3. 部署Web应用程序:将打包好的Web应用程序(通常是一个WAR文件)放置在Tomcat的webapps目录下,Tomcat会自动解压并部署该应用程序。 4. Tomcat的类加载机制:Tomcat使用了一个叫做Catalina的类加载器层次结构,按照一定的顺序加载类。其中,Common类加载器加载Tomcat共享的类库,Catalina加载器加载Tomcat内部使用的类库,Web应用程序类加载器加载各个Web应用程序中的类。 5. 连接池:Tomcat提供了连接池的功能,用于管理数据库连接。通过配置数据源和连接池参数,可以提高数据库连接的性能和效率。 6. Tomcat的日志:Tomcat会记录各种日志信息,包括访问日志、错误日志等。这些日志文件位于Tomcat安装目录下的logs文件夹中。 7. 虚拟主机:Tomcat支持虚拟主机,即在同一个Tomcat实例中运行多个独立的Web应用程序。通过配置不同的域名或端口,可以将请求分发到不同的虚拟主机上。 这些只是Tomcat的一些基础知识点,希望能对你有所帮助!如果你还有其他问题,可以继续提问。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值