From a JSP page or servlet, how may I know the root context of the current web application ? I need to know this to specify the correct href even if the context may change when my app is deployed in the production environment.

Luigi Viggiano

You can retrieve it with request.getContextPath().
If your application is in the root context it simply returns an empty string (not null).

You may change your jsp page to include the context as in the following example:

  <a href="<%= request.getContextPath() %>/index.jsp">