Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to access applications without configuring application names in big data

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how big data does not configure the application name to access the application. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have some understanding of the relevant knowledge after reading this article.

How to access the application directly through the name of the virtual host or the bound domain name without using the application name?

People who develop and deploy Web often have the above questions. In the release of Web applications, requests for applications are often required in the following form.

Virtual host + port + application name

If we configure a specific virtual host for the application, there is only one application on a virtual host, and then accessing it through the application name is unnecessary and cumbersome at the same time.

So in Tomcat, how to configure to support direct access to the application through a virtual host (port 80 can also be skipped)?

In the official documentation, the attribute of the application name in Context is described as follows:

We see that if we want to configure the default application for the virtual host, we can configure the path for context to be empty. Note here that empty means empty string, not unspecified. Of course, for the application name, we usually specify it in the form of / abc, so if it is empty, we can also specify it as /

Therefore, it is configured in the following two forms, both of which are OK.

Of course, in addition to the above configuration, naming the applied WAR package or directory ROOT can also play the above role. The ROOT application that comes with Tomcat in the webapps directory is an example.

Let's take a look at how this logic is handled within Tomcat.

First of all, when Server starts, it will involve the deployment of the application and the deployment process. You can refer to the previous article:

How WEB applications are deployed

In the process of deployment, the corresponding application name will be obtained according to the configuration of the specific Context, so as to configure and register the application name.

The following is the name of the application that resolved the configuration before deployment:

When deploying, the situation varies depending on whether the deployment is configured in server.xml or in the automatic deployment directory:

Configuration in the configuration file:

Let's see that the class ContextName, which represents the application name, contains the following declaration:

Public static final String ROOT_NAME = "ROOT"

At the same time, when the application is deployed and the specific Context name is obtained, the corresponding ContextName constructor has the following logic

Public ContextName (String path, String version) {

/ / Path should never be null,'/'or'/ ROOT'

If (path = = null | | "/" .equals (path) | | "/ ROOT" .equals (path)) {

This.path = ""

} else {

This.path = path

}

Meanwhile, for

We found that for ROOT applications, in another constructor, the request path that corresponds directly to it is empty.

If (ROOT_NAME.equals (tmp2)) {

Path = ""

}

The path here will be used for subsequent Context registration. For the registration process here, please refer to the previous article:

Tomcat multi-virtual host configuration and its principle

We see that during the registration process, if there is a path of /, it will also be automatically converted to an empty string.

If it does not match, the default value of a will be matched to 0, which is the first application. What is the first application?

This is the default application we configured, the one with empty path.

For example, the following is the path of several applications that come with Tomcat, which is registered in mapper.

So, after configuring to an application where the default path is empty, it will be used for subsequent responses to requests.

Big data on how not to configure the application name to access the application to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report