Configure Tomcat

 

  Modify Tomcat port                            

After installing Tomcat, the default port is 8080, so how to change it to the port you want?

First enter the Tomcat installation directory, then enter the conf directory

conf directory

Then open it and change the 8080 port to the port you want to set

Save the changes and then restart the service. . .

  Configure virtual hosts                                

When Tomcat is installed, it can be accessed through localhost:8080 or 127.0.0.1:8080, but what if you don't like localhost or 127.0.0.1? It does not matter! This can be achieved by modifying the configuration

The same is to enter , change the localhost in the Host tag to the name you want, such as www.jinxin.com

changed to

Of course, this is not enough, you also need to go to the system directory C:\Windows\System32\drivers\etc to change the hosts file

Open the hosts file and add a line 127.0.0.1 www.jinxin.com at the end

After restarting the Tomcat service and entering www.jinxin.com:8080 in the browser, you will find that you can also access it. Of course, you cannot access it using localhost:8080. . .

  Add administrator                                     

After entering localhost:8080 in the browser, you can click the Manager App  button on the page to log in, so how should this account be configured?

The same is to enter the conf directory, but this time it is opened , and after opening, add an administrator on the line above the </tomcat-users> tag inside 

Add method:

<role rolename="manager-gui" /> -- role
<user username="tomcat" password="tomcat" roles="manager-gui" /> -- account, this line adds an account named tomcat, password for tomcat user

After adding

After adding, save it, restart the service, and then click the Manager App button in the browser to log in. After logging in, the following page will be displayed

  Configure virtual directory                                

There are four ways to configure virtual directories, which will be listed below.

  method one              

1. Enter the conf directory, openit, and add a <Context> tag under the <Host> tag

changed to

Where path indicates that the name of the project is JavaWebApp, and docBase indicates that the location of the project is F:\Project

2. Create a Project directory according to the path in docBase

3. Try adding some content in the Project, such as creating an index.html file

 

4. Go to the browser and visit localhost:8080/JavaWebApp/index.html

The display content is as above, success!

  Method 2               

1. Enter the conf directory, then enter the Catalina directory, then enter the localhost directory, and then change the directory to create a project.xml file and write the content:

<Context docBase="F:/Project" />, where docBase represents the project path, and the project name is project

2.  Create a Project directory according to the path in docBase

3.  Try adding some content in the Project, such as creating an index.html file

4.  Go to the browser and visit localhost:8080/project/index.html

The above page is displayed, and the test is successful!

  way three              

1.  Enter the conf directory, then enter the Catalina directory, then enter the localhost directory, and then change the directory to create a ROOT.xml file (thefile name cannot be changed, it must be ROOT.xml), write the content:

<Context docBase="F:/Project" />, where docBase represents the project path

2.  Create a Project directory according to the path in docBase

3.  Try adding some content in the Project, such as creating an index.html file

4.  Go to the browser to visit localhost:8080/index.html

The above page is displayed, and the test is successful!

  Method 4 (playing the war package)            

1.  Open the war package, enter Eclipse or MyEclipse, and click the project name

 

2.  Right click and select export, select WAR file

 

3. After clicking, the following page will appear

Web Project: war package name

Destination: export path

After selecting , click Finish

4.  Put the war package into the webapps to start the service

 

5.  Enter localhost:8080/Test/index.jsp in the browser to test

So far, the four ways Tomcat creates virtual directories have all been introduced.

  myeclipse deploy Tomcat                                      

1. Open MyEclipse and come to the Servers window. If not, you can click window ==> Show View ==> Servers in the menu bar to find it

Without Servers

2. Right-click in the blank space of the Servers column and selectNew==>Servers

3. After clicking, a window will appear, select the Tomcat8 column (you do not have to select 8, it is selected according to the Tomcat version installed on the computer), and clickNext >

4. Select the path of Tomcat and JDK in the window that appears later, and click Next >after selecting

5. Then clickFinish

At this point, MyEclipse deploys Tomcat to complete

  Deploy the project                                        

After Tomcat is deployed, the project can be deployed to Tomcat, so how to deploy?

1. Find the Servers column, you can see the Tomcat just deployed

2. 鼠标右击刚刚部署好的Tomcat,选择 Add/Remove Deployments...

3. 选择后会弹出一个窗口,窗口左边是可以部署的项目

4. 双击想要部署的项目,项目会自动移动右边

5. 最后点击 Finish 即可

 

Guess you like

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