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

Some points on using standard HTML codes in web page creation

The most common mistake made by many website desi...

Detailed explanation of json file writing format

Table of contents What is JSON Why this technolog...

How to use CSS to center a box horizontally and vertically (8 methods)

Original code: center.html : <!DOCTYPE html>...

A Guide to Optimizing High-Performance Websites

Golden Rules of Performance: Only 10% to 20% of e...

js realizes the magnifying glass effect of shopping website products

This article shares the specific code of js to ac...

Docker image loading principle

Table of contents Docker images What is a mirror?...

Bootstrap+Jquery to achieve calendar effect

This article shares the specific code of Bootstra...

Share some tips on using JavaScript operators

Table of contents 1. Optional chaining operator [...

Analysis and solution of abnormal problem of loading jar in tomcat

Description of the phenomenon: The project uses s...

Implementation of CSS text shadow gradually blurring effect

text-shadow Add a shadow to the text. You can add...

A detailed discussion of evaluation strategies in JavaScript

Table of contents A chestnut to cover it Paramete...

Solution to the problem of null column in NOT IN filling pit in MySQL

Some time ago, when I was working on a small func...

Thinking about grid design of web pages

<br />Original address: http://andymao.com/a...

Getting Started Tutorial on Animating SVG Path Strokes Using CSS3

Without relying on JavaScript, pure CSS is used t...