No context path returns the name of your app as seen in the URL.
I.E: in <a href="http://localhost:8080/<b rel="nofollow">MyApp</b>/mainpage.jsp" target="_blank">
http://localhost:8080/MyApp/mainpage.jsp
"MyApp" is your contextPath.
getRealPath, on the other hand, returns the path on the server's file system leading to your application
if the app is being run as an exploded file system.
If your app has been deployed as war file, getRealPath will return null.