• 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: ools2apache-tomcat-8.5.31webapps2web上下文;

  • 相关阅读:
    新的开始
    react的setState使用中遇到的问题
    h5的input的required使用中遇到的问题
    vue学习中v-if和v-show一起使用的问题
    异步 JavaScript 之 macrotask、microtask
    .eslintrc 文件
    Vue2学习结合bootstrapTable遇到的问题
    Vue2学习(3)
    ES6 箭头函数
    Vue2学习(2)
  • 原文地址:https://www.cnblogs.com/YuyuanNo1/p/10386873.html
Copyright © 2020-2023  润新知