In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you about the implementation analysis of WelcomeFile. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
In Web applications, we often send requests in a format similar to the following:
Host:port/context/dir/
Of course, sometimes those up to the dir layer bring it, and sometimes they directly request the root application. At this time, the application server needs to determine in which form the corresponding request is displayed, such as a request for a directory. At this time, if a specific page is included in the directory, it may be to request the page or to list the directory.
At this point, you need to use Welcome File in the Web application.
With regard to Welcome File, the Servlet specification indicates that it is an ordered list of partial request paths specified in the web description file. It is mainly used to append when the request points to a directory entry and is not associated with any Web component, so as to determine the address of the specific request.
For example, in our above request form, if the dir does not correspond to any Servlet or Jsp at this time, and there is a welcomeFile configuration such as index.html, it will help direct the request.
If the above request does not correspond to the WelcomeFile, the list of request directories will be made according to the configuration of the application server (if this operation is set to allow, you can check the previous article about List how does Tomcat respond to static resources?), or directly return 404.
It is also very easy to configure WelcomeFile in the application. You only need to specify it directly in web.xml. The format is as follows, which is described in the specification:
Suppose we specify the following form of welcomeFile in our application
Index.html default.jsp
If the application directory structure contains the following dir / test/index.html / test/a.jsp / hello/x.jsp / hello/default.jsp
At this point, when we request to the test directory of the application, we will be pointed to index.html. The request hello will be pointed to default.jsp
Let's take a look at the corresponding WelcomeFile implementation in Tomcat.
What we configure in the web.xml description file will be parsed and configured when the application is deployed. Welcome-file-list is no exception. The first priority will be specified within the application. If it is not explicitly specified in the application, the configuration in the conf/web.xml provided by the application server by default is used.
The configuration in web.xml will be saved to a Set
At deployment time, add to the StandardContext
Later, when a request is received, you need to determine the specific request path and the configuration of the welcomeFile.
We have written several requests and virtual hosts in the previous article.
How to access the application without configuring the application name?
Facade Mode and request processing
Tomcat multi-virtual host configuration and its principle
It all mentions a component called Mapper. People, like their names, serve as guidelines for us. In the request process, basically follow this process:
EndPoint-> Processor-> CoyoteAdapter-> Mapper-> Pipeline-> Valve...
Here Mapper wrote in our previous article that requests will be judged based on registered virtual hosts and applications. For the welcome mentioned in this article, it is handled in the process after judgment.
Judgment is made from front to back according to different matching rules:
Exact Match
Prefix Match
Extension Match
Welcome resources processing for servlets
Welcome resources processing for exact macth
Welcome resources processing for prefix match
Welcome resources processing for physical folder
Default servlet
The above logic basically carries out different match according to the requested path. The more important point is here:
As we mentioned earlier, it will be append to the current request path when using welcomeFile to determine the request.
The above is the WelcomeFile implementation analysis shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.