URL:/contextPath/servletPath/pathInfo
Jetty
If there is no contextPath, the root context is used by default, and the path to the root context is "/".
In the absence of XML IoC files:
- If the WAR file name is, then the context path is: /myapp;
- If the WAR file name is, then the context path is:/;
- If the WAR file name is, then the context path is / and the virtual host is foobar.
WEB-INF/
<Configureclass=""> <Setname="contextPath">/test</Set> ... </Configure>
Tomcat
A separate <context> element can be defined in a number of ways:
- Defined in the /META-INF/ file of the web application, when the copyXML attribute of the Host is true, the file will be copied to the $CATALINA_BASE/conf/[enginename]/[hostname] directory and renamed. The naming specification refers to the description of the /META-INF/ section.
- Place an XML file directly under the $CATALINA_BASE/conf/[enginename]/[hostname] directory. Refer to the description of the META-INF/ subsection. This file has a higher priority than /META-INF/.
- Define a <Context> element in the <Host> element of the Tomcat server's conf/file.
META-INF/
There is a close relationship between Context name, context path, contextversion and base file name:
- If there is no contextversion, then the context name and context path are the same;
- If contextpath is an empty string, base name is ROOT;
- If contextpath is not an empty string, base name=context path, where the first/character has been removed and the /character has been replaced with the # character.
Give an example:
Context Path | Context Version | Context Name | Base File Name | Example File Names (.xml, .war & directory) |
/foo | None | /foo | foo | , , foo |
/foo/bar | None | /foo/bar | foo#bar | foo#, foo#, foo#bar |
Empty string | None | Empty String | ROOT | , , ROOT |
/foo | 42 | /foo##42 | foo##42 | foo##, foo##, foo##42 |
/foo/bar | 42 | /foo/bar##42 | foo#bar##42 | foo#bar##, foo#bar##, foo#bar##42 |
Empty string | 42 | ##42 | ROOT##42 | ROOT##, ROOT##, ROOT##42 |
Not recommendedAdd the <context> element in the conf/ file, because only by restarting Tomcat can this file be reloaded, which affects the normal use of other WebAPPs.
default
Tomcat has the default context element, which is suitable for all applications, but it has the lowest priority and all configurations can be covered by the application.
There are two default ones:
- One is $CATALINA_BASE/conf/, and the information in this context element will be loaded by all applications;
- One is $CATELINA_BASE/conf/[enginename]/[hostname]/. The information in this <context> element will be loaded by all applications in this virtual host.
This is the article about the detailed explanation of the Context Path case in Web applications. For more content on setting Context Path in related Web applications, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!