Home  >  Q&A  >  body text

What is the use of Tomcat Context

What is the use of the sub-element Context in the Host in the Tomcat server.xml file? It seems that its function can be achieved without using this element, such as this

       <Host name="localhost"  appBase="/web/webapps"unpackWARs="true"
                autoDeploy="true">
         <Context path=""    docBase="/ROOT"/>
         <Context path="app2" docBase="/app2"/>
      </Host>

There are two folders ROOT and app2 in my webapps directory. I can access the application
http://localhost:8080/app2/
like this, but if I remove the Context

       <Host name="localhost"  appBase="/web/webapps"unpackWARs="true"
                autoDeploy="true">
      </Host>

It can also be accessed in this way, so what is the use of this Context?

滿天的星座滿天的星座2686 days ago662

reply all(2)I'll reply

  • 大家讲道理

    大家讲道理2017-06-12 09:29:53

    Have you configured this app2 in web.xml, so you can access it

    reply
    0
  • 漂亮男人

    漂亮男人2017-06-12 09:29:53

    There are several ways to deploy java web to tomcat

    1. Package the project directly into the webapps directory. This method is relatively simple and convenient, but the disadvantage is that it is too rigid. The project can only be placed in webapps

    2. Use the virtual path, which is the context node you mentioned here. This method is more flexible than the above method. The project can be placed anywhere on the hard disk. The deployment can be completed by configuring the context. If you need to cancel the deployment, just delete the configuration

    reply
    0
  • Cancelreply