How does java understand that the path in the browser http: // localhost: 8080 / index is index.html? Currently it only opens for me if I explicitly register http: // localhost: 8080 / index.html
- All right It should be so. By itself, the server will not show the query index index.html. It must somehow be configured to perform such a substitution. It depends on what server, what index.html is a static file or is it formed by a servlet? - Sergey
- Tomcat server on Spring Boot e. Html Static - Ivasoft
- If static, then probably look for a rewrite rule. I don’t know if there is such a function in tomcat or spring, but I have come across references to some solutions. A particularly sophisticated way is to install revers proxy in front of tomcat (for example, nginx), they can accurately rewrite everything. The point is to replace the index request with index.html and see the server index.html (about which he knows everything) - Sergey
- The question does not apply to either Java or JavaScript, or even to HTML, but to the configuration of the server that provides the file. - Alexey Ivanov
- Tomcat is probably a java and servlet container for java, Spring is probably a well-known java framework. It is unlikely that someone unfamiliar with this jav will undertake to configure this server. Especially when the url rewrite is implemented in it by some third-party filter, also on java. Everywhere this java. - Sergey
2 answers
There is such a thing as Content Negotiation : depending on the parameters that the client sends, the server selects the most suitable content for the client that meets all the requirements. For example, there may be two files on the site:
- index.html
- index.txt
If the client requests index without an extension and specifies in the request
Accept: text/html then the server will select index.html .
In Apache servers, the mod_negotiation module is responsible for this choice. Such a "substitution" of content must be explicitly enabled on the server.
See also: Content Negotiation on Tomcat
RewriteRule can also be used for this conversion.
- About content negotiation info faster for general erudition. Dubious attitude to the problem outlined. And all sorts of rewrite - the right direction. And BalusC is authoritative. - Sergey
If you have a standard Java Web application, then in the WEB-INF/web.xml you can explicitly specify which file name to substitute by default. This is done as follows:
<welcome-file-list> <welcome-file>/index.html</welcome-file> </welcome-file-list>