Tomcat文件夹下conf文件夹中的context.xml文件存在的目的是什么
2017-12-07 14:43
686 查看
问题:
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?因为path,context标签下是不是指定了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
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?因为path,context标签下是不是指定了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
相关文章推荐
- Tomcat的conf文件夹中的web.xml文件作用
- tomcat conf目录下web.xml tomcat-users.xml server.xml context.xml这四个文件的作用
- JSP 自己写的在JSP页面得到文件的服务器路径,并对XML文件进行读写(以对Tomcat的conf目录中的context.xml文件为例)
- JSP 自己写的在JSP页面得到文件的服务器路径,并对XML文件进行读写(以对Tomcat的conf目录中的context.xml文件为例)
- tomcat conf目录下web.xml,tomcat-users.xml,server.xml,context.xml四个文件的作用
- tomcat 在META-INF 文件夹中添加context.xml,使项目自动应用更新文件
- JSP 自己写的在JSP页面得到文件的服务器路径,并对XML文件进行读写(以对Tomcat的conf目录中的context.xml文件为例)
- JSP 自己写的在JSP页面得到文件的服务器路径,并对XML文件进行读写(以对Tomcat的conf目录中的context.xml文件为例)
- JSP 自己写的在JSP页面得到文件的服务器路径,并对XML文件进行读写(以对Tomcat的conf目录中的context.xml文件为例)
- Tomcat中配置JNDI时涉及conf文件夹下的context.xml配置
- 【2011/2/28】关于Tomcat的conf/server.xml文件中上面配置 context的reloadable属性的时候,区分path和docBase二者的意义
- eclipse启动Tomcat的时候提示我缺少server.out.xml文件是什么意思?
- 2.配置DBCP:TOMCAT-HOME/webapps/项目名/META-INF/context.xml与TOMCAT-HOME/conf/Catalina/localhost/项目名字.xml
- tomcat conf目录下web.xml,tomcat-users.xml,server.xml,context.xml四个文件的作用
- tomcat中conf文件夹下的web.xml
- Tomcat启动时,spring加载配置文件applicationContext.xml出错,抛出nested exception is og.xml.sax.SAXParseException
- tomcat conf目录下 web.xml tomcat-users.xml context.xml的作用
- 在conf 文件夹的 server.xml 是 Tomcat 最为重要的配置,下面是 server.xml 的常用设置:
- Tomcat配置文件server.xml中host和context