ServletContext.getContextPath()
This returns the application context path (or "" for the root context). Inside the servlet container, none of the two applications will ever have the same value for this.
EDIT:
And for those who donβt know what the context path is: this is the URI prefix for the application. In most cases, the default is the name of the war file unless you configure it explicitly. Therefore, if you have foo.war, then you will get access to it at http://localhost:8080/foo/ , and the above function will return "/ foo".
source share