All most all JSPs invariably contain script or link tags. Say, for example, we have the following in our JSP
This is fine as long as you are running the application under root context. Now, tomorrow, say you want to run the application under context “bar”, then your are in big trouble as you have to go to all the JSPs and change the script tag to include the bar application context, as below
So, how do we make our JSPs independent of the application context?
Include the application context path in the script tag as below and you no longer have to worry about the application context.
pageContext.request.contextPath gives you the context of the application.