Tomcat文件夹下conf文件夹中的context.xml文件存在的目的是什么

来源:互联网 发布:剑灵身体数据 编辑:程序博客网 时间:2024/06/05 18:05

问题:

Tomcat文件夹下conf文件夹中的context.xml文件存在的目的是什么?



回答:

首先,你要明白一点tomcat的工作原理是什么?也是一个Java程序是一个网络服务

那么,webapp是如何嵌入的?反射

webapp是如何加载的?webapp的入口?是servlet和过滤器以及监听器这是一个webapp的入口

一个webapp又被称为什么?在tomcat中被抽象成什么对象?是ServletContext

假如,你的tomcat下部署了两个webapp最终你的tomcat中是不是管理了两个ServletContext对象每一个对象代表一个webapp

现在的问题是,为什么建立2个,而不是3个tomcat启动之后为什么会建立这样两个对象Tomcat文件夹的conf文件夹中的server.xml里面配置了context标签tomcat启动的时候会读取这个文件发现配置了2个context那么就应该建立两个ServletContext对象

 

为什么不同的url会跑到不同的ServeltContext因为pathcontext标签下是不是指定了path这样,在tomcat内部就是维护了一个map每个context对应一个path这样,tomcat接受到请求,读取url就会把这个请求交给指定的ServletContext但是,ServletContext粒度很大一个ServeltContext下管理了很多个serlet还需要进一步路由这个路由规则由谁指定?是不是每个ServletContext内部还会维护一个路由这个路由就是每个项目的WEB-INF文件夹下的web.xml也就是说    项目里的web.xml  是来管理自己项目中的东西的某个具体项目的WEB-INF文件夹下的web.xml的范围是这个项目ServletVontext的内部级别

 

 

WEB-INF文件夹下的web.xml是不是配置了不同的sevlet的mapping,全部由这个文件来指定。那么,tomcat为什么知道是这个文件?这些都需要tomcat这个java程序来读取来分配来指定规则因为Tomcat文件夹下的conf文件夹中的context.xml中指定了这个web.xml的路径如图:(context.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.--><!-- The contents of this file will be loaded for each web application --><Context>    <!-- Default set of monitored resources. If one of these changes, the    -->    <!-- web application will be reloaded.                                   -->    <WatchedResource>WEB-INF/web.xml</WatchedResource>    <WatchedResource>WEB-INF/tomcat-web.xml</WatchedResource>    <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>    <!-- Uncomment this to disable session persistence across Tomcat restarts -->    <!--    <Manager pathname="" />    --></Context>

 

 

假如你把红线那一行改了你改成web2.xml那么,你的webapp中也要相应的改成web2.xml

阅读全文
0 0
原创粉丝点击