Thank you Bauke for the prompt reply.
Can the values returned by the HttpServletRequest#getContextPath() and ServletContext#getContextPath() be different in any case?
Generally, we give the context path in the application.xml(In case of
JBoss and Websphere).Lets say for a Test.war, we give the context path as /Test in the application.xml.
Now a call to ServletContext#getContextPath() made by a Servlet in Test.war, would get the "/Test".
Also, when a resource under the Test.war needs to be accessed,the Servlet path should be prefixed with "/Test".If the context path in the URL is differnt, then the request would not be routed to the TestWar.
So, since both the method(HttpServletRequest#getContextPath() and ServletContext#getContextPath()) return the same result, why do we have them both in the api?
Or is there any scenario for which the results of the above mentioned methods could vary?