Detailed explanation of how to solve the conflict of project URLs caused by setting the default path of Tomcat

Detailed explanation of how to solve the conflict of project URLs caused by setting the default path of Tomcat

Preface

Tomcat is an excellent Java container, but there are still some small pitfalls that cannot be avoided. I will record them here.

START

question

  • URL path conflicts after deploying multiple projects

Scenario Description

1. There are two projects under webapps, projectA and projectB. Except for the management information interface, the other two projects have security verification mechanisms.

2. Since projectA is not separated from the front-end and back-end, the static resources also exist in the Java project. When making interface requests in static resources, the package name is not written. For example, when logging in, the js code will concatenate the server ip+port+currently set url (/login), but not add /projectA before /login. Therefore, there is no problem in testing on the local machine, and such a problem will only occur when deploying. This is also a problem, which will be solved below.

3.projectB is a normal running project

Solution for scenario 2

Open the configuration file in tomcat, add <Context> in the <Host> tag to set it as the default access path of the server, so as to avoid the package name, but this method is extremely informal and is not recommended.

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

    <!-- 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
       Note: The pattern used is equivalent to using pattern="common" -->
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
        prefix="localhost_access_log" suffix=".txt"
        pattern="%h %l %u %t &quot;%r&quot; %s %b" />
    <Context path="" docBase="/usr/tomcat8.6/webapps/sc_edu" debug="0" reloadable="true"/>

  </Host>

Code Explanation

<Context path="" docBase="/usr/tomcat8.6/webapps/sc_edu" debug="0" reloadable="true"/>
  • path and doBase together indicate the specified package path. For simplicity, you can directly uninstall docBase.
  • Restart tomcat and test that the resources in the package can be accessed directly by ip+port. However, when accessing resources in other packages, url ambiguity will occur. Originally, I wanted to access projectB, but it was mapped to projectA. Only some urls will have such problems.

Then our solution is to install another tomcat and only deploy projects that require direct path mapping

This will return to the directory where tomcat is located, and the cp command will copy

$> cp -r tomcat8.5/ tomcat8.6/

Then move projectA in tomcat8.5 to tomcat8.6.

Delete the tomcat8.5

<Context path="" docBase="/usr/tomcat8.6/webapps/sc_edu" debug="0" reloadable="true"/>

In tomcat8.6, the following changes need to be made to service.xml.

Change the port corresponding to shutdown to 8006, as long as it is different from tomcat8.5 and the port does not conflict.

<Server port="8006" shutdown="SHUTDOWN">

Change the port corresponding to the request, the principle is the same as above

<Connector port="8081" protocol="HTTP/1.1"
        connectionTimeout="20000"
        redirectPort="8443" />

The content in the <Host> tag is copied and needs to be modified to the corresponding mapping path.

In this way, two tomcats can run at the same time, and startup and shutdown do not affect each other.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Analysis and solution of abnormal problem of loading jar in tomcat
  • Detailed understanding and comparative analysis of servers Apache, Tomcat and Nginx
  • Explanation of several ways to run Tomcat under Linux
  • How to set up virtual directories and configure virtual paths in Tomcat 7.0
  • Explanation of Tomcat using IDEA remote Debug
  • Tomcat uses Log4j to output catalina.out log
  • Connector configuration in Tomcat
  • Explanation on the use and modification of Tomcat's default program publishing path
  • Detailed steps for importing eclipse projects into IDEA and deploying them to tomcat
  • Solution to Tomcat server failing to open tomcat7w.exe

<<:  MySQL 5.7.18 download and installation process detailed instructions

>>:  Vue+canvas realizes the effect of refreshing waterfall chart from top to bottom in real time (similar to QT)

Recommend

How to create a child process in nodejs

Table of contents Introduction Child Process Crea...

Detailed explanation of the use of React.cloneElement

Table of contents The role of cloneElement Usage ...

How to enter directory/folder in Linux without using CD command

As we all know, without the cd command, we cannot...

Understanding and example code of Vue default slot

Table of contents What is a slot Understanding of...

Detailed explanation of the use of MySQL DML statements

Preface: In the previous article, we mainly intro...

Detailed explanation of the watch listener example in vue3.0

Table of contents Preface The difference between ...

CSS3 overflow property explained

1. Overflow Overflow is overflow (container). Whe...

How to redirect to other pages in html page within two seconds

Copy code The code is as follows: <!DOCTYPE ht...

JavaScript adds event listeners to event delegation in batches. Detailed process

1. What is event delegation? Event delegation: Ut...

JavaScript BOM location object + navigator object + history object

Table of contents 1. Location Object 1. URL 2. Pr...

A brief discussion on MySQL large table optimization solution

background The amount of new data in the business...