tomcat如何在server.xml中配置contexts
https://tomcat.apache.org/tomcat-8.5-doc/deployer-howto.html#A_word_on_Contexts
例如你的程序 名字是hello端口是80 这时候你要访问你的程序 就要用 localhost/hello 来访问了。
但是怎么直接用 localhost来访问呢?就需要进行tomcat 的配置了呢
看以下配置:tomcat里面conf 里的server.xml 最下面
<Host name="localhost" appBase=""
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<!-- 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 -->
<!--
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
-->
<Context docBase="webapps/hello" path="/hello" reloadable="true" ></Context>
<Context docBase="webapps/hello" path="/" reloadable="true" ></Context>
<Context docBase="webapps/cas" path="/cas" reloadable="true" ></Context>
</Host>
这里原来带有的appBase是有值的 是webapps 这里的意思 是加载webapps下面所有的项目,等于是只要你放到webapp里面的项目都会被加载,(这里我就不写了 我在下面写了配置让他加载)
然后你自己可以写 context来写你的项目,docBase可以写绝对地址也可以写相对地址,相对地址是相对于你的tomcat来说的,这里 写为webapps/hello意思就是 webapp下面的 hello;
这里要说一下 启动的时候加载两遍的问题 当你appBase里面写 过webapps 的话 他会先自动加载一所有的然后加载你配置的。所以你不想他加载两遍 你就可以 在appBase里面什么也不写。
但是这样会遇到一个问题,就是 当我用struts跳转的时候,你发现 不不配置 <Context docBase="webapps/hello" path="/hello" reloadable="true" ></Context>这个的时候 你的项目会找不到struts的返回页面,这就是弊端,你想通过不输入项目名字访问项目,但是你的程序会找不到result,所以你还得写上原来的映射,这样你访问的首页是通过<Context docBase="webapps/hello" path="/" reloadable="true" ></Context>这个访问的,但是里面的一些跳转是根据<Context docBase="webapps/hello" path="/hello" reloadable="true" ></Context>他来跳转的。所以还是加载了两遍,。这里要根据你的项目来决定。
、、、、、、、、、、、、、、、、、、、
注意:
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<!-- <Context docBase="webapps/hello" path="/hello" reloadable="true" ></Context> -->
<Context docBase="fxgk_test" path="/fxgk2" reloadable="true" ></Context>
这里appBase已经设置为webapps,所以Context里面的配置不需要加前缀 webapps/ 了;
这里的 appBase 可以设置为 其它目录 ,比如 webapps2 那么 项目的所在路径就相应的改为 了 E:\tools2\apache-tomcat-8.5.31\webapps2\web上下文;
tomcat如何在server.xml中配置contexts的更多相关文章
- tomcat启动了server.xml中没有配置的项目
在tomcat的conf目录下的server.xml文件中没有配置hczm_struts项目,但在eclipse启动tomcat调试时,一直启动hczm_struts项目. 经检查,发现conf\Ca ...
- JavaWeb 如何在web.xml中配置多个servlet
15:34:42 <servlet> <description></description> <display-name>ListMusicServle ...
- tomcat访问manager报404;server.xml中配置了Context path
<Context path="" docBase="crm" debug="0" reloadable="true" ...
- JNDI在server.xml中的配置(全局和局部的)
总结: 全局就是在数据源server.xml中配置,然后通过和项目名相同的xml来进行映射.对所有的项目都起作用.那个项目需要就在对应的tomcat下配置一个与项目名相同的xml映射文件. 局部的就是 ...
- tomcat 的配置文件 server.xml 详解
server.xml位于$TOMCAT_HOME/conf目录下,作为整个 tomcat 服务器最核心的配置文件,server.xml的每一个元素都对应了 tomcat中的一个组件,通过对xml中元素 ...
- tomcat的配置文件server.conf中的元素的理解
tomcat的配置文件server.conf中的元素的理解 tomcat作为一个servlet服务器本身的配置文件是tomcat_home/conf/server.conf,这个配置文件中有很多元素, ...
- Tomcat server.xml中Connector配置参数详解
Tomcat中Connector常用配置 Tomcat中server.xml有些配置信息是需要我们了解的,最起码知道如何进行简单的调试. <Connector port="8080&q ...
- Tomcat下server.xml中context介绍
conf/Context.xml是Tomcat公用的环境配置;若在server.xml中增加<Context path="/test" docBase="D:\te ...
- eclipse配置tomcat后修改server.xml文件(如编码等)无效问题
我们用eclipse配置好tomcat后,在处理中文乱码或是配置数据源时,我们要修改Tomcat下的server.xml等文件. 修改后重启Tomcat服务器时发现xml文件又被还原了. 因为Tomc ...
随机推荐
- mysql5.7报err 1055错误 sql_mode=only_full_group_by
vim /etc/my.cnf 末尾增加 sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_B ...
- linux性能采用工具oprofile使用
1.先收藏几篇博文,先解决问题,周末继续. http://www.cnblogs.com/bangerlee/archive/2012/08/30/2659435.html http://blog.s ...
- MSVC 12: compiler error in boost/type_traits/common_type.hpp
来自: https://svn.boost.org/trac10/ticket/11885 MSVC 12: compiler error in boost/type_traits/common_ty ...
- Java 终于有 Lambda 表达式啦~Java 8 语言变化——Lambda 表达式和接口类更改【转载】
原文地址 en cn 下载 Demo Java™ 8 包含一些重要的新的语言功能,为您提供了构建程序的更简单方式.Lambda 表达式 为内联代码块定义一种新语法,其灵活性与匿名内部类一样,但样板文件 ...
- JS中的HTML片段
经常在js里面写一些html模板,但是由于语法不同,没有办法啊直接将html黏贴在js中. var html = "<!DOCTYPE html>"+ "&l ...
- Spring4学习笔记一:环境搭建与插件安装、基本概念理解
一:环境搭建 1:开发环境:JDK安装.Eclipse安装 2:数据库:Mysql.Sequel Pro(数据库可视化操作工具) 3:web服务器:Tomcat下载,并且把tomcat配置到Eclip ...
- 移除list中null元素
查询结果为null, list.size()却是1 移除该null元素 totalList.removeAll(Collections.singleton(null));
- JDK自带的运行监控工具JConsole观察分析Java程序的运行
原文地址:https://blog.csdn.net/libaolin198706231987/article/details/55057149 一.JConsole是什么 从Java 5开始 引入了 ...
- spring-mybatis-data-common程序级分表操作实例
spring-mybatis-data-common-2.0新增分表机制,在1.0基础上做了部分调整. 基于机架展示分库应用数据库分表实力创建 create table tb_example_1( i ...
- 12C -- ORA-65048 ORA-65048
创建common user的时候报错: $ sqlplus '/as sysdba' SQL*Plus: Release 12.2.0.1.0 Production on Tue Apr 18 11: ...