title: How to get domain URL and application name?
body: <p>Here's the scenario.</p>
  
  <p>My Java web application has following path</p>
  
  <pre><code>https://www.mywebsite.com:9443/MyWebApp
  </code></pre>
  
  <p>Let's say there is a JSP file</p>
  
  <pre><code>https://www.mywebsite.com:9443/MyWebApp/protected/index.jsp
  </code></pre>
  
  <p>and I need to retrieve </p>
  
  <pre><code>https://www.mywebsite.com:9443/MyWebApp 
  </code></pre>
  
  <p>within this JSP file.</p>
  
  <p>Of course, there is rather a lazy and silly way of just getting the URL and then re-tracing the path back.</p>
  
  <p>But is there a programatic way of doing this? Specifically, I think I can get the domain + port, but how do I actually retrieve the application name "MyWebApp"?</p>