How Tomcat publishes web projects

 The tomcat/webapps directory is used to store Java projects. Each folder is a project. By default, there are already four projects in this directory, all of which come with tomcat.

Among them, ROOT is the main project of Tomcat that we access when we test Tomcat. If we want to create our own project, we need to follow the JavaEE directory structure rules.

method one:

Take the Hello project as an example:

  Hello project name, must have, create a new folder named Hello under webapps

     |----------Store WEB resources (such as: jsp, html, css, etc.), such as creating a new hello.xml

     |----------WEB-INF Required and must be capitalized The files in this directory are protected and cannot be accessed directly

    |---------web.xml must have, the configuration file of the web project

    |----------classes Stores the .class file edited by the java class

    |----------lib stores the third-party dependencies that need to be introduced

 

Access items:

1) Start tomcat

2)访问:http://localhost:8080/hello/hello.html

 

If it is a static page, there is no need to restart tomcat. If it is a dynamic page, such as jsp, you need to restart tomcat and recompile.

 

Method two:

Put the project in any directory, and then configure <Context path="" docBase=""> under the host tag of server.xml

1) The path attribute gives the virtual path of the project, which can be filled in at will, such as /abc (/ must have)

2) The docBase attribute specifies the real storage path of the project

For example, the project is placed under F:\hello1, then write: <Context path="/abc" docBase="F:/hello1"/>

Note: Once the docBase path is specified, when restarting tomcat, it will not look for the project under webapps, but lock the project location through docBase

访问URL:http://localhost:8080/abc/hello.html

 

Method three:

Create a Catalina directory in the conf directory, and create a new localhost directory in this directory

 Create a new one in the localhost directory, such as: def.xml, the content is: < Context  docBase= "F:/hello1"  /> 

No need to write path, the virtual directory is the file name def, path defaults to /def, adding def.xml does not require restarting the tomcat server

访问URL:http://localhost:8080/def/hello.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324849515&siteId=291194637