Context Path



The context path is also known as context root is the portion of the request URL that indicates the context of the request i.e. the application to be accessed.

eg:
"http://www.mydomain.com:8080/myWebApp/index.html"

The context path is default taken as the application name.
It can be configured in application.xml of the EAR file or web.xml of the WAR application.

If there are multiple applications deployed on the application server then it acts as an address of the application to be accessed.

All applications have a unique context root.

Some application servers ask the context root while deployment of the application.

J2EE (now called Java EE) application servers can host more than one "webapp".
The portion of the URI just after the port (shown in bold) is known as the contextPath for a webapp.

In this case 'index.html' is in root directory of the webapp called myWebApp.

To fetch the context path or context root in jsp below is the snippet used.
The <%=request.getContextPath ( )> is used to return the portion of the request URL and specifies the context of the request.  

Comments

Popular Posts