getRealPath() in ServletRequest is deprecated. You have to use the getRealPath(String path) method of the ServletContext object instead. This would return you the absolute path to the resources of the web application on the container that hosts it.
getContextPath() returns the context portion of the request uri. So a call to getContextPath() in index.jsp with the url, http://<m/c> ort/web_app/jsp/index.jsp would return /web_app/jsp.
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.