That certainly is a disconnect from your first post which asked about the web app display name, not the context path.
In any case, what you've got coded won't work in the general case. It will only work when the context path coincides with the file path of the web app, which is often not the case in production.
Rather,
you should investigate getRealPath().